SwooleRuntime
Serves requests from an embedded Swoole HTTP server.
Two things make Swoole different from the other hosts:
-
It forks its worker processes when start() is called, i.e. after the app has bootstrapped and possibly opened database connections. Every child would inherit the same sockets and interleave on the wire, so
WorkerLoop::bootWorker()runs onworkerStart— that is whatforksWorkers: truein the capabilities is for. -
Coroutines are switched off, deliberately. Quiote keeps process-global state (Config, Context, PluginManager, RoutingCallbackPool, LogContext, $_SESSION, the hydrated superglobals), so two requests interleaving inside one process would cross-contaminate all of it — log lines attributed to the wrong user, session data leaking between requests. SWOOLE_BASE with
enable_coroutine => falsegives exactly the same one-request-at-a-time semantics as FrankenPHP and RoadRunner.
Detection requires an explicit opt-in via $QUIOTE_WORKER_RUNTIME, unlike RoadRunner: see SwooleRuntime::isSupported().
Synopsis
Section titled “Synopsis”final class SwooleRuntime implements WorkerRuntimeInterface
| Implements | WorkerRuntimeInterface |
| Source | SwooleRuntime.php |
Constants
Section titled “Constants”| Constant | Value | Description |
|---|---|---|
DEFAULT_HOST | '0.0.0.0' | |
DEFAULT_PORT | 8080 |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(?SwooleServerFactory $serverFactory = null): mixed
| Parameter | Type | Description |
|---|---|---|
$serverFactory | ?SwooleServerFactory |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
alias(): string | The registry alias: “swoole”. |
capabilities(): WorkerRuntimeCapabilities | Persistent, forking, off-SAPI and streaming-capable. |
detectionPriority(): int | Detection priority 100 — well above SapiRuntime’s PHP_INT_MIN, so once SwooleRuntime::isSupported() has confirmed the opt-in this runtime wins over the plain SAPI fallback. |
isSupported(): bool | extension_loaded('swoole') alone would be wrong: the extension is routinely loaded under php-fpm, and claiming the process on that basis would hijack every FPM request on such a box. |
run(WorkerLoop $loop): void | Builds the Swoole HTTP server, wires the loop into it and serves. |
settings(): array<string, mixed> |
alias()
Section titled “alias()”public static function alias(): string
The registry alias: “swoole”.
Returns string
capabilities()
Section titled “capabilities()”public function capabilities(): WorkerRuntimeCapabilities
Persistent, forking, off-SAPI and streaming-capable.
populatesSuperglobals: false and sapiOutput: false are what switch on the loop’s superglobal hydration and stray-output capture; forksWorkers: true is what makes it reset the context per worker child.
Returns WorkerRuntimeCapabilities
detectionPriority()
Section titled “detectionPriority()”public static function detectionPriority(): int
Detection priority 100 — well above SapiRuntime’s PHP_INT_MIN, so once SwooleRuntime::isSupported() has confirmed the opt-in this runtime wins over the plain SAPI fallback.
Returns int
isSupported()
Section titled “isSupported()”public static function isSupported(): bool
extension_loaded('swoole') alone would be wrong: the extension is routinely loaded under php-fpm, and claiming the process on that basis would hijack every FPM request on such a box.
Only the server itself knows it is the server, and it has no environment marker of its own — so the operator says so.
Returns bool
public function run(WorkerLoop $loop): void
Builds the Swoole HTTP server, wires the loop into it and serves.
workerStart calls WorkerLoop::bootWorker() in each forked child. Each request is converted to PSR-7, handled, and emitted through a per-request SwooleResponseEmitter; a throwable from the conversion or the emission is rendered via WorkerLoop::renderError(), and WorkerLoop::afterRequest() runs in a finally. Returns only once the server stops, after which the loop is shut down.
| Parameter | Type | Description |
|---|---|---|
$loop | WorkerLoop |
| Throws | When |
|---|---|
RuntimeException | if coroutines are enabled without the explicit worker.swoole.allow_coroutine_unsafe override, or ext-swoole is missing. |
settings()
Section titled “settings()”public static function settings(): array<string, mixed>
Returns array``<``string``, ``mixed``>
| Throws | When |
|---|---|
RuntimeException | when coroutines are enabled without an explicit override. |