文档地址:
https://wiki.swoole.com/wiki/page/326.html
创建httpServer.php
文件,代码如下:
<?php
// 创建服务对象
$http = new swoole_http_server("10.211.55.17", 9501); // 10.211.55.17是我们Swoole主机 9501是端口
// 监听request请求
$http->on('request', function ($request, $response) {
$response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
// 这一步很重要
$http->start();
2、上面代码就是swool中 http服务代码,执行文件 开启服务
php httpServer.php
3、浏览器访问 http://10.211.55.17:9501/
页面会显示:
Hello Swoole. #随机数字
说明这个http服务的可以正常访问的。