Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

ForkPool
in package

FinalYes

Host-side handle for the fork-per-request CGI runner — App::cgiMode('fork').

Spawns ONE long-lived fork_master.php template subprocess (per OpenSwoole worker, lazily) that binds a UNIX socket and forks a FRESH child per request (Apache MPM prefork). Each dispatch() opens a short-lived connection to that socket, sends one IPC request frame, and reads one response frame; the master forks a child to handle it. Fresh-process correctness (no "Cannot redeclare class") at fork cost (~1 ms), not proc_open cold-start.

The master's stdout/stderr are redirected to a LOG FILE (not a pipe): fork children inherit those fds, and an undrained pipe would fill (64 KB) and deadlock a child mid-warning. The protocol is 100% over the socket, so the std streams are diagnostics only. Readiness is detected by polling the socket (the master accepts once bound), not a stderr line.

EXPERIMENTAL. Requires pcntl + posix in the spawned PHP. See docs/architecture/2026-06-02-fork-per-request-cgi-pool.md.

Table of Contents

Properties

$maxConcurrent  : int
$proc  : resource|null
$ready  : bool
$sockPath  : string

Methods

__construct()  : mixed
__destruct()  : mixed
close()  : void
dispatch()  : array<string|int, mixed>
Dispatch one request: connect, send the frame, read the response.
isAlive()  : bool
connect()  : resource|null
defaultSockPath()  : string
respawn()  : void
spawn()  : void

Properties

$maxConcurrent read-only

private int $maxConcurrent = 16

$proc

private resource|null $proc = null

The fork_master subprocess handle.

Methods

__construct()

public __construct([int $maxConcurrent = 16 ][, string|null $sockPath = null ]) : mixed
Parameters
$maxConcurrent : int = 16
$sockPath : string|null = null

__destruct()

public __destruct() : mixed

dispatch()

Dispatch one request: connect, send the frame, read the response.

public dispatch(array<string|int, mixed> $request[, float $timeout = 30.0 ]) : array<string|int, mixed>

Respawns the master and retries once on a connection failure.

Parameters
$request : array<string|int, mixed>
$timeout : float = 30.0
Return values
array<string|int, mixed>

isAlive()

public isAlive() : bool
Return values
bool

connect()

private connect(float $timeout) : resource|null
Parameters
$timeout : float
Return values
resource|null

defaultSockPath()

private static defaultSockPath() : string
Return values
string
On this page