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

3.测试 新开用户登录在linux 环境下运行 curl http://127.0.0.1:9501 ip加端口号
获取到服务器 响应给客户端的数据

4.传递参数 的情况
在linux 环境下运行 curl http://127.0.0.1:9501?m=520 ip加端口号


5.配置域名访问
打开 安全组9501端口 域名加上端口号

6.配置静态文件
运行效果

网友评论