💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**创建HTTP服务器** ***** <br> 示例: ``` class WebServer{ private $serv = null; public function __construct(){ $this->serv = new swoole_http_server("0.0.0.0",9501); $this->serv->on("request",[$this,"onRequest"]); $this->serv->start(); } public function onRequest($request,$response){ //处理chrome请求2次的问题 if ($request->server['path_info'] == '/favicon.ico' || $request->server['request_uri'] == '/favicon.ico') { return $response->end(); } var_dump($request->get, $request->post); $response->header("Content-Type", "text/html; charset=utf-8"); $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>"); } } new WebServer(); ``` <br> ## nginx+swoole配置 Http\Server对Http协议的支持并不完整,建议仅作为应用服务器。并且在前端增加Nginx作为代理 ~~~ server { root /data/wwwroot/; server_name local.swoole.com; location / { proxy_http_version 1.1; proxy_set_header Connection "keep-alive"; proxy_set_header X-Real-IP $remote_addr; if (!-e $request_filename) { proxy_pass http://127.0.0.1:9501; } } } ~~~ > 通过读取`$request->header['x-real-ip']`来获取客户端的真实`IP`