$http = new Swoole\Http\Server('0.0.0.0', 9501);
$http->on('Request', function ($request, $response) use ($http) {
/**
* swoole http 服务的 request 中 有那些东西
* fd 客户端口唯一标识
* header 请求头信息
* server 对应 php $_SERVER
* cookie 信息 php $_COOKIE
* get 对应 php $_GET
* post 对应 Php $_POST
* files 对应 php $_FILES
* tmpfiles $_FILES 的部分数据
*/
echo json_encode($request) . PHP_EOL;
});
输出结果:
{
"fd": 1,
"header": {
"user-agent": "PostmanRuntime\/7.28.0",
"accept": "*\/*",
"postman-token": "7fde4ecd-f7fd-414f-8fe2-d45f538bae67",
"host": "localhost:9501",
"accept-encoding": "gzip, deflate, br",
"connection": "keep-alive",
"content-type": "multipart\/form-data; boundary=--------------------------070893652364061875063737",
"content-length": "12927"
},
"server": {
"request_method": "POST",
"request_uri": "\/",
"path_info": "\/",
"request_time": 1627442507,
"request_time_float": 1627442507.04809,
"server_protocol": "HTTP\/1.1",
"server_port": 9501,
"remote_port": 63532,
"remote_addr": "127.0.0.1",
"master_time": 1627442506
},
"cookie": null,
"get": null,
"files": {
"file": {
"name": "LOGO108\u00d7108.jpg",
"type": "image\/jpeg",
"tmp_name": "\/tmp\/swoole.upfile.Tg2oqu",
"error": 0,
"size": 12713
}
},
"post": null,
"tmpfiles": [
"\/tmp\/swoole.upfile.Tg2oqu"
]
}