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

API Documentation

Table of Contents

Namespaces

ZealPHP

Classes

ZealPHP_Pool_State
Loop control and the response channel, kept out of the included script's reach (C1).
ZealPHP_IPC_Sender
Destructor-based metadata frame sender. PHP runs destructors even after exit() is called from inside a shutdown function — phpMyAdmin's ResponseRenderer->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.
ZealPHP_Pool_NullSessionHandler
Save handler that stores nothing. Used only by pool_reset_session() (below) to run a throwaway session through session_destroy() without touching real data.

Constants

SID  : mixed = ''

Functions

apache_request_headers()  : array<string, string>
Return all HTTP request headers as an associative array.
getallheaders()  : array<string, string>
Alias for apache_request_headers() — both names exist under mod_php.
apache_response_headers()  : array<string, string>
Return all response headers queued for the current request.
apache_setenv()  : bool
Set a named Apache subprocess environment variable.
apache_getenv()  : string|false
Retrieve a named Apache subprocess environment variable.
apache_note()  : string
Get or set an Apache request note (named annotation attached to the request).
virtual()  : bool
Perform an Apache internal sub-request for $uri.
__z_write_meta()  : void
Write the one metadata line: to the metadata fd when the parent opened one (C7), else to stderr (the protocol before fd 3, still used by direct invocations).
__z_fire_header_callback()  : void
#357 — fire a registered header_register_callback() exactly once (mod_php keeps a single callback). Two registration sources, drained in order: (1) the subprocess-local override above, which stashes into $GLOBALS['__z_header_callback'] (the common case — autoload off); (2) the framework's utils.php header_register_callback(), active when ZEALPHP_CGI_AUTOLOAD=1, which stashes into the RequestContext memo.
__z_send_meta()  : mixed
Write the metadata frame (status, headers, cookies, optional return value) to STDERR as a single JSON line. Idempotent — subsequent calls are no-ops once $__z_meta_sent is true. Called by the flush() override and the shutdown function so the frame is always sent before the body, regardless of whether the included file streams or buffers.
apache_request_headers()  : array<string, string>
Polyfill for apache_request_headers() in CLI SAPI.
getallheaders()  : array<string, string>
Polyfill for getallheaders() in CLI SAPI — delegates to apache_request_headers().
apache_response_headers()  : array<string, string>
Polyfill for apache_response_headers() in CLI SAPI.
apache_setenv()  : bool
Polyfill for apache_setenv() in CLI SAPI.
apache_getenv()  : mixed
Polyfill for apache_getenv() in CLI SAPI.
apache_note()  : string
Polyfill for apache_note() in CLI SAPI.
virtual()  : bool
Polyfill for virtual() in CLI SAPI.
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.
pool_reset_session()  : void
Forget the previous request's session before the next one runs (H1).
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_handlers()  : void
Drop every error and exception handler the request installed, so none of them runs in the next request (C9). The worker installs none of its own.
pool_reset_env()  : void
Put the process environment back to its boot state (C9): putenv() from one request must not reach the next one, as FPM restores it at request end.
pool_reset_request_state()  : void
Reset all per-request state between pool iterations.

Constants

Functions

apache_request_headers()

Return all HTTP request headers as an associative array.

apache_request_headers() : array<string, string>

Shim for apache_request_headers() / getallheaders() on non-Apache SAPIs.

Return values
array<string, string>

getallheaders()

Alias for apache_request_headers() — both names exist under mod_php.

getallheaders() : array<string, string>

This shim makes getallheaders() available on OpenSwoole / CLI SAPIs.

Return values
array<string, string>

apache_response_headers()

Return all response headers queued for the current request.

apache_response_headers() : array<string, string>

Delegates to \ZealPHP\apache_response_headers() which reads from the per-request $g->zealphp_response header list.

Return values
array<string, string>

apache_setenv()

Set a named Apache subprocess environment variable.

apache_setenv(string $variable, string $value[, bool $walk_to_top = false ]) : bool

In ZealPHP this writes into the per-request $g->server bag under the conventional HTTP_* key so subsequent handler code sees the value.

The $walk_to_top parameter is accepted for API compatibility but has no effect (there is no parent-request scope in OpenSwoole).

Parameters
$variable : string
$value : string
$walk_to_top : bool = false
Return values
bool

apache_getenv()

Retrieve a named Apache subprocess environment variable.

apache_getenv(string $variable[, bool $walk_to_top = false ]) : string|false

Returns false when the variable is not set (matching Apache's behaviour).

The $walk_to_top parameter is accepted for API compatibility but has no effect in ZealPHP.

Parameters
$variable : string
$walk_to_top : bool = false
Return values
string|false

apache_note()

Get or set an Apache request note (named annotation attached to the request).

apache_note(string $note_name[, string|null $note_value = null ]) : string

When $note_value is null, returns the current value of the note. When $note_value is provided, sets it and returns the previous value (or an empty string when the note was not previously set).

Parameters
$note_name : string
$note_value : string|null = null
Return values
string

virtual()

Perform an Apache internal sub-request for $uri.

virtual(string $uri) : bool

In ZealPHP this dispatches the URI through the framework's routing stack in-process (similar to Apache's virtual() / mod_include sub-request mechanism). Returns true on success, false on failure.

Parameters
$uri : string
Return values
bool

__z_write_meta()

Write the one metadata line: to the metadata fd when the parent opened one (C7), else to stderr (the protocol before fd 3, still used by direct invocations).

__z_write_meta(string $json) : void
Parameters
$json : string

__z_fire_header_callback()

#357 — fire a registered header_register_callback() exactly once (mod_php keeps a single callback). Two registration sources, drained in order: (1) the subprocess-local override above, which stashes into $GLOBALS['__z_header_callback'] (the common case — autoload off); (2) the framework's utils.php header_register_callback(), active when ZEALPHP_CGI_AUTOLOAD=1, which stashes into the RequestContext memo.

__z_fire_header_callback() : void

MUST be called while the header() override is still active (right after the included file finishes) — NOT from the shutdown function: uopz tears its overrides down before register_shutdown_function runs, so header() calls inside a callback fired at shutdown would not be captured into $__z_headers.

__z_send_meta()

Write the metadata frame (status, headers, cookies, optional return value) to STDERR as a single JSON line. Idempotent — subsequent calls are no-ops once $__z_meta_sent is true. Called by the flush() override and the shutdown function so the frame is always sent before the body, regardless of whether the included file streams or buffers.

__z_send_meta() : mixed

apache_request_headers()

Polyfill for apache_request_headers() in CLI SAPI.

apache_request_headers() : array<string, string>

Reconstructs the canonical header map from $_SERVER HTTP_* keys plus CONTENT_TYPE and CONTENT_LENGTH, matching Apache mod_php behaviour.

Return values
array<string, string> —

Map of header name → value.

getallheaders()

Polyfill for getallheaders() in CLI SAPI — delegates to apache_request_headers().

getallheaders() : array<string, string>
Return values
array<string, string> —

Map of header name → value.

apache_response_headers()

Polyfill for apache_response_headers() in CLI SAPI.

apache_response_headers() : array<string, string>

Returns the response headers collected so far by the header() override.

Return values
array<string, string> —

Map of header name → value.

apache_setenv()

Polyfill for apache_setenv() in CLI SAPI.

apache_setenv(string $variable, string $value[, bool $walk_to_top = false ]) : bool

Stores $value in the subprocess-local $__z_apache_env map (Apache mod_env parity).

Parameters
$variable : string
$value : string
$walk_to_top : bool = false
Return values
bool

apache_getenv()

Polyfill for apache_getenv() in CLI SAPI.

apache_getenv(string $variable[, bool $walk_to_top = false ]) : mixed

Reads from $__z_apache_env; returns false when the variable is not set.

Parameters
$variable : string
$walk_to_top : bool = false

apache_note()

Polyfill for apache_note() in CLI SAPI.

apache_note(string $note_name[, string|null $note_value = null ]) : string

Gets/sets a named note in $__z_apache_notes. Returns the previous value (empty string if unset).

Parameters
$note_name : string
$note_value : string|null = null
Return values
string

virtual()

Polyfill for virtual() in CLI SAPI.

virtual(string $uri) : bool

Internal sub-requests are not supported in the subprocess context — always returns false.

Parameters
$uri : string
Return values
bool

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>

pool_reset_session()

Forget the previous request's session before the next one runs (H1).

pool_reset_session(array<string, string> $baseline) : void

session_write_close() saves and closes the session but leaves the module's internal id set. The next request's session_start() then reuses it instead of reading its own cookie, so a visitor with no cookie (or a different one) was handed the previous user's session — data and, via the host-emitted Set-Cookie, the id itself. FPM gets this for free from per-request module shutdown; a reused pool subprocess has to do it by hand.

PHP has no call that only clears the id: session_id('') stores an EMPTY id, which makes session_start() skip the cookie and mint a new session, so the returning owner would lose theirs. session_destroy() is the one path that resets the module's request globals (id back to NULL). So when an id is left over, start a throwaway session on a no-op save handler and destroy that; the real session's data, already written by session_write_close(), is never touched.

Then restore the session INI settings the request may have changed (session_name(), session_save_path(), session_set_cookie_params(), the save handler, ini_set), so one app's session configuration does not carry into the next request.

Parameters
$baseline : array<string, string>

session INI values at boot

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: array}

pool_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_handlers()

Drop every error and exception handler the request installed, so none of them runs in the next request (C9). The worker installs none of its own.

pool_reset_handlers() : void

PHP has no call that clears the handler stack, and set_error_handler(null) pushes the old handler instead of dropping it. Each round below sets a null handler to read the current one, undoes that push, then pops one level; it stops once no handler is left.

pool_reset_env()

Put the process environment back to its boot state (C9): putenv() from one request must not reach the next one, as FPM restores it at request end.

pool_reset_env(array<string, string> $baseline) : void
Parameters
$baseline : array<string, string>

getenv() at boot

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.

On this page