Swoole HTTP服务端测试
1.创建服务端server.php
<?php $http = new Swoole\Http\Server('0.0.0.0', 6666); $http->on('Request', function ($request, $response) { $response->header('Content-Type', 'text/html; charset=utf-8'); $request_time = $request->server; $html = 'request_time:'.json_encode($request_time); //向客户端发送HTML内容 $response->end('<h1>Hello Swoole. #' . rand(1000, 9999) . '</h1><p>1这是GET数据'.json_encode($request->get).'</p>'.$html); }); $http->start();
2.通过CURL访问端口
curl http://127.0.0.1:6666
返回数据:<h1>Hello Swoole. #4673</h1><p>1这是GET数据{"id":"2"}</p>request_time:{"query_string":"id=2","request_method":"GET","request_uri":"\/server.php","path_info":"\/server.php","request_time":1656230485,"request_time_float":1656230485.932749,"server_port":6666,"remote_port":57710,"remote_addr":"127.0.0.1","master_time":1656230485,"server_protocol":"HTTP\/1.1"}