document_root參數主要是設置訪問靜態頁面時的指定靜態文件目錄
$http = new Swoole\Http\Server("0.0.0.0", 9505);
$http->set([
'worker_num'=>5,//進程數
'enable_static_handler'=>true,//是否允許加載靜態文件 true-是 false-否
'document_root'=>'/var/www/swoole/data',//指定靜態文件目錄
]);
$http->on('request', function ($request, $response) {
//發送數據到前端
$response->end("<h1>httpserver. #".rand(1000, 9999)."</h1>");
});
$http->start();
輸入 ip或域名:9505訪問測試