API Index — Namespaces, Packages, Reports, Indices
IniIsolationMiddleware
in package
implements
MiddlewareInterface
Snapshot / restore selected php.ini values around each request.
Long-running PHP workers don't reset ini_set() changes between requests.
ini_set('date.timezone', 'Asia/Tokyo') in request N stays in effect for
request N+1 on the same worker — a footgun that only surfaces under load
when requests with different settings interleave.
This middleware snapshots a curated list of commonly-mutated INI keys at request start and restores any changes when the request completes. Defaults cover the values most apps mutate per-request; pass a custom list to the constructor to extend or replace.
Opt-in. Not registered by default — register it explicitly:
use ZealPHP\Middleware\IniIsolationMiddleware;
$app->addMiddleware(new IniIsolationMiddleware());
Or enable via env var:
ZEALPHP_INI_ISOLATE=1 php app.php
(when ZEALPHP_INI_ISOLATE=1, App::run() registers this middleware
automatically; see App.php for the registration check.)
Table of Contents
Interfaces
- MiddlewareInterface
Constants
- DEFAULT_KEYS : mixed = ['date.timezone', 'date.default_latitude', 'dat...
- INI keys that are common per-request mutation targets. These are what
we snapshot+restore by default. Anything outside this list is left
alone — partly to keep the per-request overhead bounded, partly
because keys outside this list are usually intentional process-wide
settings (
max_execution_timehas no meaning under coroutines anyway, and changing extension-loaded settings per-request is incoherent).
Properties
- $keys : array<string|int, string>
Methods
- __construct() : mixed
- process() : ResponseInterface
Constants
DEFAULT_KEYS
INI keys that are common per-request mutation targets. These are what
we snapshot+restore by default. Anything outside this list is left
alone — partly to keep the per-request overhead bounded, partly
because keys outside this list are usually intentional process-wide
settings (max_execution_time has no meaning under coroutines anyway,
and changing extension-loaded settings per-request is incoherent).
public
mixed
DEFAULT_KEYS
= ['date.timezone', 'date.default_latitude', 'date.default_longitude', 'default_charset', 'default_mimetype', 'display_errors', 'display_startup_errors', 'error_reporting', 'html_errors', 'log_errors', 'memory_limit', 'precision', 'serialize_precision']
Properties
$keys
private
array<string|int, string>
$keys
Methods
__construct()
public
__construct([array<string|int, string>|null $keys = null ]) : mixed
Parameters
- $keys : array<string|int, string>|null = null
-
INI keys to snapshot+restore. Defaults to
self::DEFAULT_KEYS. Pass an extended list to add app-specific keys; pass an empty array to disable (effectively a no-op).
process()
public
process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
- $request : ServerRequestInterface
- $handler : RequestHandlerInterface