Swoole实现简单的http服务器
2021-01-04 06:28
标签:http服务 lang response protect echo sel amp and stat Swoole实现简单的http服务器 标签:http服务 lang response protect echo sel amp and stat 原文地址:https://www.cnblogs.com/ezhar/p/13625359.htmlclass http_server
{
const HOST = "127.0.0.1";
const PORT = 8811;
protected $server = null;
public function __construct()
{
$this->server = new swoole_http_server(self::HOST, self::PORT);
$this->server->set([
"enable_static_handler" => true,
"document_root" => "./public"
]);
$this->server->on("request", [$this, "OnRequest"]);
$this->server->start();
}
public function OnRequest($request, $response)
{
$requestParametersFormClient = json_encode($request->get);
//format: http://127.0.0.1:8811/?m=1&n=2&o=3 => {"m":"1","n":"2","o":"3"}
echo "request parameters from server is: " . $requestParametersFormClient . "\n";
$response->end("ended!");
}
}
new http_server();
文章标题:Swoole实现简单的http服务器
文章链接:http://soscw.com/index.php/essay/39985.html