Skip to content

WorkerRuntimeCapabilities

What a WorkerRuntimeInterface can and cannot do, so the shared WorkerLoop knows which compensations to install rather than every runtime re-deciding.

The distinction that matters most is $populatesSuperglobals + $sapiOutput: a real SAPI (php-fpm, php -S, FrankenPHP) refills $_SERVER/$_GET/… per request and lets header()/echo reach the client, while a CLI-hosted server (RoadRunner, Swoole) does neither — it hands over a request object and takes a response object. Everything the loop does to bridge that gap (superglobal hydration, output capture, native session-cookie synthesis) keys off these two flags.

final readonly class WorkerRuntimeCapabilities

SourceRuntime/Worker/WorkerRuntimeCapabilities.php
PropertyTypeDescription
$forksWorkersboolreadonly.
$persistentboolreadonly.
$populatesSuperglobalsboolreadonly.
$sapiOutputboolreadonly.
$streamingboolreadonly.

public function __construct(bool $persistent, bool $populatesSuperglobals, bool $sapiOutput, bool $streaming, bool $forksWorkers): mixed

Worker processes are forked after bootstrap, so bootWorker() must run per child.

ParameterTypeDescription
$persistentboolThe process survives across requests, so per-request state must be reset.
$populatesSuperglobalsboolThe runtime fills $_SERVER/$_GET/$_POST/$_COOKIE/$_FILES itself.
$sapiOutputboolecho/header()/http_response_code() reach the client.
$streamingboolThe response body can be flushed incrementally (SSE).
$forksWorkersboolWorker processes are forked after bootstrap, so bootWorker() must run per child.

Returns mixed

MethodDescription
sapi(bool $persistent = false): WorkerRuntimeCapabilitiesThe classic single-request SAPI shape: nothing persists, the SAPI owns input and output.

public static function sapi(bool $persistent = false): WorkerRuntimeCapabilities

The classic single-request SAPI shape: nothing persists, the SAPI owns input and output.

Also the correct answer for a FrankenPHP worker apart from $persistent, hence the parameter.

ParameterTypeDescription
$persistentbool

Returns WorkerRuntimeCapabilities