创建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服务的可以正常访问的。

相关文章:

  • 2021-04-08
  • 2022-12-23
  • 2021-09-16
  • 2021-12-30
  • 2021-09-06
  • 2022-12-23
  • 2021-06-02
  • 2021-09-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2021-07-12
  • 2021-04-14
相关资源
相似解决方案