美文网首页程序员
swoole_http_server客户端测试

swoole_http_server客户端测试

作者: zhaoxiaohui520 | 来源:发表于2020-07-01 00:03 被阅读0次

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
520.png
3.测试 新开用户登录在linux 环境下运行 curl http://127.0.0.1:9501 ip加端口号
获取到服务器 响应给客户端的数据
1.png
4.传递参数 的情况
在linux 环境下运行 curl http://127.0.0.1:9501?m=520 ip加端口号
53.png 3.png
5.配置域名访问
打开 安全组9501端口 域名加上端口号
7.png
6.配置静态文件

运行效果


6.png

相关文章

网友评论

    本文标题:swoole_http_server客户端测试

    本文链接:https://www.haomeiwen.com/subject/zulqqktx.html