Superglobals

OxPHP populates every standard PHP superglobal before your script executes, the same way a traditional server setup does. Values are available from the first line of your code, and you do not need to initialize anything. Only one setting narrows that; see Disabling superglobals.

$_SERVER

OxPHP builds $_SERVER from the incoming request following the CGI/1.1 specification, on top of the process environment. Every key it sets, how request headers map to HTTP_* keys, the values behind a reverse proxy, PATH_INFO, and the differences from PHP-FPM are listed in Server Variables.

$_GET

Query string parameters are parsed automatically from the request URI.

php
<?php // Request: GET /search?q=oxphp&page=2 $query = $_GET['q']; // "oxphp" $page = $_GET['page']; // "2"

Array syntax works as expected:

php
<?php // Request: GET /filter?tags[]=php&tags[]=async $tags = $_GET['tags']; // ["php", "async"]
What filter_input(INPUT_GET, …) sees

filter_input(), filter_input_array() and filter_has_var() do not read $_GET, $_POST or $_COOKIE. They read a copy of the parsed input that the filter extension keeps. OxPHP resets that copy at the start of each request, so these functions answer for the current request and no other.

In worker mode the copy belongs to whichever request last started or resumed on the worker. If your request pauses (sleep(), an await, a hooked call) and another request runs on that worker meanwhile, filter reads after the resume return null. $_GET, $_POST and $_COOKIE travel with the request across a suspension, so read those, or call the filter functions before you suspend.

A FILTER_CALLBACK in a per-field filter_input_array() definition cannot pause at all. An explicit Fiber::suspend() in it throws, and any I/O it does holds the worker thread until it returns. Requests queued behind it wait, and past their wait budget they are shed. The callback's client sets how long that lasts: default_socket_timeout (60 seconds by default) for stream wrappers, mysqlnd.net_read_timeout (a day by default) for mysqlnd. Give such a call an explicit timeout, or run checks that reach a database or a cache after filter_input_array() returns.

$_POST

OxPHP supports the two standard content types for form submissions:

  • application/x-www-form-urlencoded: standard HTML form data
  • multipart/form-data: file uploads combined with form fields
php
<?php // Request: POST /login // Content-Type: application/x-www-form-urlencoded // Body: username=admin&password=secret $username = $_POST['username']; // "admin" $password = $_POST['password']; // "secret"

For JSON or other content types, use php://input instead:

php
<?php // Request: POST /api/users // Content-Type: application/json // Body: {"name":"Alice","email":"alice@example.com"} $data = json_decode(file_get_contents('php://input'), true); $name = $data['name']; // "Alice" $email = $data['email']; // "alice@example.com"
Note

filter_input(INPUT_POST, …) reads the filter extension's own copy of the body, not $_POST. See the note under $_GET for how long that copy lasts.

Cookies are parsed from the Cookie request header.

php
<?php // Request with: Cookie: session=abc123; theme=dark $session = $_COOKIE['session']; // "abc123" $theme = $_COOKIE['theme']; // "dark"

Two kinds of cookie never reach PHP:

  • Reserved names. The __oxp_ prefix is reserved for internal OxPHP plugins, and those cookies are stripped from the Cookie header before PHP sees it. So is any name PHP would register under that prefix, since PHP turns a space, a dot or an unmatched [ into _: __oxp.x is stripped, and so are array names such as __oxp[a] and _[oxp_t].
  • Non-ASCII headers. A Cookie header holding a byte outside ASCII is dropped whole, with no log message. $_COOKIE is empty, $_SERVER['HTTP_COOKIE'] is not set, and the request object finds no cookies and no cookie header. Plugins see no cookies on that request either.

filter_input(INPUT_COOKIE, …) reads the filter extension's own copy of the cookies, not $_COOKIE; see the note under $_GET.

$_FILES

File uploads sent via multipart/form-data populate the $_FILES array with the standard PHP structure:

php
<?php // $_FILES['avatar'] structure: // [ // 'name' => 'photo.jpg', // Original filename sent by the client // 'type' => 'image/jpeg', // MIME type declared by the client // 'tmp_name' => '/tmp/phpAb12Cd', // Temporary file path on the server // 'error' => 0, // UPLOAD_ERR_OK (0 means no error) // 'size' => 204800, // File size in bytes // ] if ($_FILES['avatar']['error'] === UPLOAD_ERR_OK) { $tmp = $_FILES['avatar']['tmp_name']; $name = basename($_FILES['avatar']['name']); move_uploaded_file($tmp, "/uploads/$name"); }

$_REQUEST

PHP merges $_GET, $_POST and $_COOKIE into $_REQUEST by its usual rules: in the order the request_order INI directive lists them (variables_order when request_order is not set), with a later source overwriting a key an earlier one set.

Cookies are included, and they win

The OxPHP images load no php.ini: php.ini-production and php.ini-development sit unused in /usr/local/etc/php (see Installation). So request_order is unset, and PHP falls back to its built-in variables_order, "EGPCS": GET, then POST, then COOKIE. A cookie replaces a query or body value of the same name. When both are arrays (k[a] in the body, k[b] in a cookie), they merge key by key under the same rule.

The request_order = "GP" you may know from PHP-FPM setups comes from those sample files, not from PHP itself. To leave cookies out, set request_order = "GP" in an ini file loaded at startup, such as /usr/local/etc/php/conf.d/zz-request-order.ini. ini_set() cannot change this directive at runtime.

php
<?php // POST /form?action=preview with body action=submit $action = $_REQUEST['action']; // "submit" — POST overrides GET // Same request, also carrying the header "Cookie: action=delete" $action = $_REQUEST['action']; // "delete" — the cookie overrides both
Worker mode

$_REQUEST is rebuilt for every request. PHP normally builds it once, when a script that mentions it is first loaded, so in a persistent worker every later request would read the first one's parameters. OxPHP forces the rebuild.

$_ENV

$_ENV holds the process environment. In traditional mode PHP rebuilds it on every request, subject to variables_order, as under PHP-FPM. Unlike under PHP-FPM, that environment belongs to the whole server process; see putenv() below.

Worker mode keeps it. .env loaders (vlucas/phpdotenv, symfony/dotenv, Laravel's Env) write their values into $_ENV during bootstrap, and by default only Laravel's also calls putenv(). Rebuilding $_ENV per request would erase that configuration from the second request on. So in worker mode, once the array exists, it lives as long as the worker, and every write into it stays visible to every later request on that worker.

php
<?php // bootstrap, before oxphp_worker() Dotenv\Dotenv::createImmutable(__DIR__)->load(); // writes into $_ENV oxphp_worker(function () { echo $_ENV['DATABASE_URL']; // still there on request 10_000 });
In worker mode $_ENV is worker state

OxPHP keeps the whole array and cannot tell a bootstrap write from a handler write. $_ENV['tenant_id'] = $request->tenant(); in a request handler stays for the rest of the worker's life, and every later request on that worker reads it. So does a request the worker takes on while the writer is paused at a suspension point, because a suspended request does not carry $_ENV with it. Nothing is logged.

Write to $_ENV from your bootstrap only, and keep per-request values somewhere rebuilt per request:

  • $_SERVER, which also travels with its request across a suspension;
  • the attributes container on OxPHP's request object, as long as you pass that object along (oxphp_http_request() builds a fresh Request, with an empty container, on every call);
  • anything your framework scopes to the request. A container binding or a request stack set up once during bootstrap is worker state, with the same reach as $_ENV.
What filter_input(INPUT_ENV, …) sees

filter_input(INPUT_ENV, …), filter_input_array(INPUT_ENV) and filter_has_var(INPUT_ENV, …) read the environment snapshot PHP took when it built $_ENV, not $_ENV itself, so values written into the array are not among them. PHP behaves this way everywhere. In worker mode the snapshot is taken once per worker, so a later putenv() is missing from it too. getenv() reads the live environment.

Keeping $_ENV relies on PHP's default auto_globals_jit=1. With auto_globals_jit=0, PHP rebuilds $_ENV from the process environment on every request, and a .env loader's values do not survive in worker mode.

putenv()

putenv() writes the process environment, not $_ENV. The variable is set for the whole server process: getenv() reads it, and a child process started without an $env array of its own inherits it. When the request ends, OxPHP puts back what the request set, in both modes. In worker mode the value it restores is the one the bootstrap left before oxphp_worker() (see Worker State Between Requests). An oxphp_async() task is the exception: it runs on an async worker thread, and what it sets stays for the life of that thread.

Until the request ends, the value is the whole process's:

  • Requests running at the same time on other workers read it with getenv(), and their child processes inherit it. Under PHP-FPM, with every worker a process of its own, they would not.
  • In worker mode, so do the requests the same worker runs while the setter is paused.
  • A $_ENV built while the value is set picks it up: for the rest of that request in traditional mode, and for the life of the worker in worker mode.
  • Two threads that set the same name share it. If the one that set it first also puts it back first, it restores the value from before both, for the whole process, while the other still has it set.

Keep a value that belongs to one request out of the environment. Pass it to a child process in the $env argument of proc_open(), and keep it in an ordinary variable everywhere else.

php://input

The raw request body is available through the php://input stream. This is the standard way to read JSON payloads, XML, or any content type other than form submissions.

php
<?php $body = file_get_contents('php://input'); $data = json_decode($body, true);

php://input is rewindable and can be read multiple times within the same request.

Note

php://input is empty for multipart/form-data requests. Use $_POST and $_FILES for those.

Disabling superglobals

Set SUPERGLOBALS_ENABLED=false to stop OxPHP describing the request to PHP: the CGI and HTTP_* variables are not registered, and the query string is not handed over to be parsed. Use the HTTP Request API (oxphp_http_request()) to access request data instead.

bash
SUPERGLOBALS_ENABLED=false # the $_SERVER request keys and $_GET are not built

It reaches fewer of these arrays than the name suggests. The request body and the Cookie header are handed to PHP either way, so everything PHP builds out of them is there as usual:

What With SUPERGLOBALS_ENABLED=false
$_GET Empty
$_SERVER During a request, only REQUEST_TIME, REQUEST_TIME_FLOAT, argc and argv, all set by PHP itself. REQUEST_METHOD, REQUEST_URI, the HTTP_* keys and the process environment are absent
$_POST, $_FILES, $_COOKIE Populated as usual
$_REQUEST Populated, merged by PHP as always (see $_REQUEST); only what $_GET would have contributed is missing
$_SESSION Filled by PHP's session module when a request starts a session, not by the SAPI
php://input A stream, not a superglobal; readable as usual
header(), headers_list(), etc. SAPI functions, not superglobals
session_start() and other session_*() functions Native PHP functions
oxphp_http_request() Available; every method answers, including query() and payload()

In worker mode the bootstrap is the exception. The code above oxphp_worker() runs before any request and sees a $_SERVER built as though the setting were on, with the whole process environment and a placeholder REQUEST_URI of /.

Routing on REQUEST_URI

Code that routes on $_SERVER['REQUEST_URI'] finds nothing there under this setting and has to read oxphp_http_request()->path() instead. In a worker entry script this applies to the handler. The bootstrap's placeholder / is not the real route either.

You can check the current setting at runtime:

php
if (!oxphp_superglobals_enabled()) { $request = oxphp_http_request(); $page = $request->query('page', 1); }

Prompts for your agent

These prompts assume an agent with the OxPHP documentation MCP server connected. The agent reads the pages it needs itself.

prompt
My application under OxPHP worker mode is losing values it read through `filter_input()`. Read the `php/superglobals` page through the OxPHP documentation MCP server. Check my code for `filter_input()` and `filter_input_array()` calls made after the request can pause on I/O or a suspended Fiber, and for `FILTER_CALLBACK` validators that do I/O, then tell me which calls to move or replace with `$_GET`, `$_POST` or `$_COOKIE` reads.
prompt
Check my worker-mode application for request state leaking through the environment. Read the `php/superglobals` page through the OxPHP documentation MCP server. Find every write into `$_ENV` and every `putenv()` call that runs inside a request handler rather than the bootstrap, and tell me where each value should live instead.

See also

Found a mistake? Report it