swoole的http服务

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_35979073/article/details/102778330

 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访问测试

猜你喜欢

转载自blog.csdn.net/qq_35979073/article/details/102778330