Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-25.2.0 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Http\Request->server: array
None
Array
The OpenSwoole\Http\Request->server class property is an array which contains the information of HTTP server request, it is the equivalent to the PHP super global variable $_SERVER, you should use this instead.
All the array keys are lowercase. This array contains server request information like URL, request method and IP information...
Server Array
query_string: The request GET query parameters from the URL.request_method: The HTTP request method that was used, GET, POST, PUT etc.request_uri: The actual request URL/path, this can be used for URL routing, contains no GET parameterspath_info: Same as request_uri but contains the GET parameters in the addressrequest_time: A timestamp of when the request was dispatched to a worker process not the actual full packet/request time. Because this time is set when the request is dispatched to a worker, the time can deviate from when the request is actually processed. For a more accurate request time, use $server->getClientInfo() to obtain last_time insteadrequest_time_float: The timestamp of the start of the request in microseconds, using a float type, for example 1576220199.2725server_protocol: The server protocol HTTP version number, for example HTTP/1.0, HTTP/1.1 or HTTP/2server_port: The port that the server is listening onremote_port: The port which the client is using to connect to the serverremote_addr: The client IP address. You may need to get the IP from the headers if you are behind a load balancermaster_time: The client connection last communication timestamp<?php
$server->on('Request', function(OpenSwoole\Server\Request $request, OpenSwoole\Server\Response $response)
{
// Array keys are lowercase
echo $request->server['request_time'];
echo $request->server['request_uri'];
// See the whole request server array
var_dump($request->server);
});