API Index — Namespaces, Packages, Reports, Indices
pool_worker.php
Persistent subprocess entry for ZealPHP's native FCGI-style worker pool.
Loops on stdin frames: read request payload → execute the PHP file → write
response frame to stdout → reset request state → next iteration. Exits
cleanly on EOF (parent closed the pipe) or after ZEALPHP_POOL_MAX_REQUESTS
requests (FPM pm.max_requests parity recycle).
Each iteration is approximately what cgi_worker.php does for ONE request,
but without the per-request boot cost — Composer autoloader, uopz overrides,
and the IPC class stay loaded across iterations. That's what the pool buys
over cgiMode('proc') (where every request pays ~30-50 ms cold-start PHP).
Caveat for unmodified WordPress / Drupal: PHP's global namespace (defined
classes, define() constants, ini_set) PERSISTS across iterations of the
SAME worker. Setting ZEALPHP_POOL_MAX_REQUESTS=1 recycles after each
request → true fresh-process semantics, identical to cgiMode('proc') but
with the parent pool managing spawn cost amortisation. K > 1 (default 500)
is for apps with idempotent boot — modernised legacy or framework code
that guards defined() ?: define(). WordPress itself emits E_NOTICE on
re-define but continues fine (notice ≠ fatal), matching FPM behavior.
uopz overrides: header(), header_remove(), setcookie(), setrawcookie(), http_response_code(), headers_list(), headers_sent() — same shape as src/cgi_worker.php's captures so the response frame can be threaded back through the parent worker's response builder unchanged.
Table of Contents
Classes
- ZealPHP_IPC_Sender
- Destructor-based metadata frame sender. PHP runs destructors even after
exit()is called from inside a shutdown function — phpMyAdmin'sResponseRenderer->response()does exactly that. The shutdown chain gets preempted, but a destructor on a static instance still fires, so the parent receives status/headers/cookies regardless of how the request ended.
Functions
-
pool_prepare_request()
: array{file: string, prevCwd: mixed}|array{__error: array
} - Prepare per-request state and return the file to include + the prior cwd.
- pool_finish_request() : array<string, mixed>
- Capture output and build the response AFTER the global-scope include.
- pool_reset_request_state() : void
- Reset all per-request state between pool iterations.
Functions
pool_prepare_request()
Prepare per-request state and return the file to include + the prior cwd.
pool_prepare_request(array<string|int, mixed> $req) : array{file: string, prevCwd: mixed}|array{__error: array}
The include itself is performed by the CALLER at GLOBAL scope (see the
request loop) — NOT here — so a legacy app's top-level variables
($menu / $submenu in WP's wp-admin) become real $GLOBALS. Including from
inside a function made them function-locals, so WP's global $menu resolved
to null and uksort($menu, …) fataled. [Issue 1: include scope]
Parameters
- $req : array<string|int, mixed>
Return values
array{file: string, prevCwd: mixed}|array{__error: arraypool_finish_request()
Capture output and build the response AFTER the global-scope include.
pool_finish_request(mixed $result, Throwable|null $error, mixed $prevCwd) : array<string, mixed>
Parameters
- $result : mixed
-
the include's return value (null if it threw)
- $error : Throwable|null
-
exception thrown by the include, if any
- $prevCwd : mixed
-
cwd to restore
Return values
array<string, mixed>pool_reset_request_state()
Reset all per-request state between pool iterations.
pool_reset_request_state() : void
Clears superglobals ($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES,
$_REQUEST, $_SESSION), the raw input buffer, response capture state
($__pw_headers, $__pw_cookies, $__pw_rawcookies, $__pw_status),
any queued shutdown functions, and all output buffers.
Performs FPM-style $GLOBALS cleanup (unsets request-scope keys not in
the boot snapshot) and, when ext-zealphp is loaded, calls
zealphp_process_state_clean() to roll back constants, classes, functions,
and included files to the boot baseline.
When ZEALPHP_POOL_FULL_RESET=1 is set, also resets op_array
run_time_cache, function-local statics, and class static properties
(mirrors CoSessionManager's per-request reset stack from ext-zealphp 0.3.25).
IMPORTANT: Must be called at GLOBAL SCOPE (not inside a function) so that
$_SESSION = null and the superglobal resets take effect process-wide.