1.http_server.php 文件内容
<?php
<?php
$http=new swoole_http_server("0.0.0.0",9501);
//配置静态文件根目录,与 enable_static_handler 配合使用。
$http->set(
[
'enable_static_handler'=>true,
'document_root'=>"/usr/local/nginx/html/swoole/data",
]
);
//请求响应
$http->on('request', function ($request, $response) {
var_dump($request->get, $request->post);
$response->header("Content-Type", "text/html; charset=utf-8");
$response->end("<h1>Hello Swoole_http_server. #".rand(1000, 9999)."</h1>");
});
//打开服务
$http->start();
2.打开http服务 linux下 php http_server.php
![](https://img.haomeiwen.com/i19403812/3b6ab925a1492c41.png)
3.测试 新开用户登录在linux 环境下运行 curl http://127.0.0.1:9501 ip加端口号
获取到服务器 响应给客户端的数据
![](https://img.haomeiwen.com/i19403812/84468e39e095437d.png)
4.传递参数 的情况
在linux 环境下运行 curl http://127.0.0.1:9501?m=520 ip加端口号
![](https://img.haomeiwen.com/i19403812/b0ef0c617bbada1b.png)
![](https://img.haomeiwen.com/i19403812/ef34c8491c97bbe9.png)
5.配置域名访问
打开 安全组9501端口 域名加上端口号
![](https://img.haomeiwen.com/i19403812/a762371b2545986d.png)
6.配置静态文件
运行效果
![](https://img.haomeiwen.com/i19403812/ee1bde44d04df7d9.png)
网友评论