swoole the http service

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_35979073/article/details/102778330

 document_root main parameter is set to specify a static file directory when accessing static pages

$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();

Enter the domain name or ip: 9505 Access test

Guess you like

Origin blog.csdn.net/qq_35979073/article/details/102778330