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

fork_master.php

Apache MPM prefork for ZealPHP — the fork-per-request CGI runner (EXPERIMENTAL).

A long-lived TEMPLATE process (NO OpenSwoole reactor — pcntl_fork() is unsafe inside the reactor) binds a UNIX socket and forks a FRESH child per accepted request. The child:

  1. runs the target file AT TRUE GLOBAL SCOPE (this script's top level), so a legacy app's top-level variables ($menu/$submenu in WP's wp-admin) become real $GLOBALS and global $menu resolves — the issue #167 fix;
  2. captures output/status/headers/cookies (uopz/ext-zealphp overrides);
  3. writes the response frame, then HARD-exits (posix_kill SIGKILL — no PHP shutdown / destructors that could flush COW-shared resources and corrupt the parent). All its define()/class declarations die with it.

The parent never runs app code, so every fork starts from the same clean, warm baseline: fresh-process correctness (no "Cannot redeclare class") at fork cost (~1 ms COW) instead of proc_open cold-start (~30-50 ms).

Protocol: one length-prefixed JSON request frame in, one response frame out, per connection (the same IPC framing the pool uses).

Wiring/host side is ForkPool. NOTE: the capture-override block below is intentionally duplicated from pool_worker.php for this first experimental cut (zero regression risk to the production pool); it will be de-duplicated into a shared runtime once fork mode is validated.

Requires: pcntl + posix. Env: ZEALPHP_FORK_SOCK (unix socket path), ZEALPHP_FORK_MAX_CONCURRENT (live-child cap, default 16), ZEALPHP_CWD.

Table of Contents

Functions

fork_prepare_request()  : string|null
Populate request superglobals + php://input from a request frame. Returns the absolute file to include, or null on a bad/missing file. (The include itself is done by the CALLER at top-level scope — see the loop — so the included file's top-level variables become real $GLOBALS.)
fork_build_response()  : array<string, mixed>
Build the response frame from the captured state + the include's output.

Functions

fork_prepare_request()

Populate request superglobals + php://input from a request frame. Returns the absolute file to include, or null on a bad/missing file. (The include itself is done by the CALLER at top-level scope — see the loop — so the included file's top-level variables become real $GLOBALS.)

fork_prepare_request(array<string|int, mixed> $req) : string|null
Parameters
$req : array<string|int, mixed>
Return values
string|null

fork_build_response()

Build the response frame from the captured state + the include's output.

fork_build_response(mixed $result, string $body) : array<string, mixed>
Parameters
$result : mixed

the include's return value

$body : string
Return values
array<string, mixed>
On this page