标签:http服务 lang response protect echo sel amp and stat
class 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();
标签:http服务 lang response protect echo sel amp and stat
原文地址:https://www.cnblogs.com/ezhar/p/13625359.html