OpenSwoole\Http\Request->server

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Http\Request->server: array

Parameters

None

Return

Array

Description

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 parameters
  • path_info: Same as request_uri but contains the GET parameters in the address
  • request_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 instead
  • request_time_float: The timestamp of the start of the request in microseconds, using a float type, for example 1576220199.2725
  • server_protocol: The server protocol HTTP version number, for example HTTP/1.0, HTTP/1.1 or HTTP/2
  • server_port: The port that the server is listening on
  • remote_port: The port which the client is using to connect to the server
  • remote_addr: The client IP address. You may need to get the IP from the headers if you are behind a load balancer
  • master_time: The client connection last communication timestamp

Example

<?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);
});
Last updated on September 20, 2022