Skip to content

FrankenPhpRuntime

FrankenPHP worker mode: a persistent process that parks in frankenphp_handle_request() and gets its superglobals refilled per request.

FrankenPHP is a real SAPI, so this is the one persistent runtime that keeps every SAPI-shaped assumption — header()/echo work, superglobals arrive populated, flush() streams — and the loop’s off-SAPI compensations stay switched off.

final class FrankenPhpRuntime implements WorkerRuntimeInterface

ImplementsWorkerRuntimeInterface
SourceRuntime/Worker/FrankenPhpRuntime.php

public function __construct(Closure(callable): bool|null $handleRequest = null, ResponseEmitterInterface $emitter = new SapiEmitter(…)): mixed

Injectable so the loop is testable without FrankenPHP; defaults to the real extension function.

ParameterTypeDescription
$handleRequest`Closure(callable): bool““null`
$emitterResponseEmitterInterface

Returns mixed

MethodDescription
alias(): stringThe registry alias: “frankenphp”.
capabilities(): WorkerRuntimeCapabilitiesSAPI-shaped and persistent: superglobals and output work natively, across many requests.
detectionPriority(): intDetection priority 100 — well above SapiRuntime’s PHP_INT_MIN, so a FrankenPHP worker always wins over the plain SAPI fallback.
isSupported(): boolTrue when the FrankenPHP extension is present, detected by the existence of frankenphp_handle_request().
run(WorkerLoop $loop): voidBoots the worker, then serves requests from frankenphp_handle_request().

public static function alias(): string

The registry alias: “frankenphp”.

Returns string

public function capabilities(): WorkerRuntimeCapabilities

SAPI-shaped and persistent: superglobals and output work natively, across many requests.

Returns WorkerRuntimeCapabilities

public static function detectionPriority(): int

Detection priority 100 — well above SapiRuntime’s PHP_INT_MIN, so a FrankenPHP worker always wins over the plain SAPI fallback.

Returns int

public static function isSupported(): bool

True when the FrankenPHP extension is present, detected by the existence of frankenphp_handle_request().

That function only exists inside a FrankenPHP worker process, so no opt-in environment marker is needed.

Returns bool

public function run(WorkerLoop $loop): void

Boots the worker, then serves requests from frankenphp_handle_request().

Each iteration builds the request from the refilled superglobals, runs it through the loop and emits the response; WorkerLoop::afterRequest() runs in a finally so a failed emission still resets request state. The loop ends when FrankenPHP asks the worker to stop or the max-requests budget is spent, and WorkerLoop::shutdown() is called on the way out.

ParameterTypeDescription
$loopWorkerLoop