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.
Synopsis
Section titled “Synopsis”final class FrankenPhpRuntime implements WorkerRuntimeInterface
| Implements | WorkerRuntimeInterface |
| Source | Runtime/Worker/FrankenPhpRuntime.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”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.
| Parameter | Type | Description |
|---|---|---|
$handleRequest | `Closure(callable): bool“ | “null` |
$emitter | ResponseEmitterInterface |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
alias(): string | The registry alias: “frankenphp”. |
capabilities(): WorkerRuntimeCapabilities | SAPI-shaped and persistent: superglobals and output work natively, across many requests. |
detectionPriority(): int | Detection priority 100 — well above SapiRuntime’s PHP_INT_MIN, so a FrankenPHP worker always wins over the plain SAPI fallback. |
isSupported(): bool | True when the FrankenPHP extension is present, detected by the existence of frankenphp_handle_request(). |
run(WorkerLoop $loop): void | Boots the worker, then serves requests from frankenphp_handle_request(). |
alias()
Section titled “alias()”public static function alias(): string
The registry alias: “frankenphp”.
Returns string
capabilities()
Section titled “capabilities()”public function capabilities(): WorkerRuntimeCapabilities
SAPI-shaped and persistent: superglobals and output work natively, across many requests.
Returns WorkerRuntimeCapabilities
detectionPriority()
Section titled “detectionPriority()”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
isSupported()
Section titled “isSupported()”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.
| Parameter | Type | Description |
|---|---|---|
$loop | WorkerLoop |