<?php
class HTTP{
private $http = null;
public function __construct(){
$this->http = new Swoole\Http\Server('0.0.0.0', 9501);
/*
$this->http->set([
'worker_num' => 4, // worker process num
'max_request' => 50,
]);
*/
$this->http->on('request',[$this,"onRequest"]);
$this->http->start();
}
public function onRequest($request, $response){
$response->header('Content-Type', 'text/html; charset=utf-8');
$response->end('<h1>Hello Swoole. #' . rand(1000, 9999) . '</h1>');
}
}
new HTTP();
# php HTTP.php
如果出现无法访问情况,注意查看端口号开放
访问http://42.192.180.238:9501/
Hello Swoole. #9853