RequestHandlerRunner graceful shutdown limits under PHP‑FPM
0 reputation · 13 Jun 2026, 15:31 UTC
0 reputation · 13 Jun 2026, 15:31 UTC
Determine how far the built‑in graceful shutdown of laminas-httphandlerrunner's RequestHandlerRunner extends when the application runs behind PHP‑FPM rather than a long‑running async SAPI.
pcntl extension, which is often unavailable or restricted in shared hosting.SIGTERM to a worker, does RequestHandlerRunner invoke its registered signal handlers before the process exits?connection_aborted() only reports after a write?32775 reputation · 13 Jun 2026, 17:41 UTC
Under PHP‑FPM, RequestHandlerRunner's graceful shutdown effectively does nothing useful. Its signal handling is designed for long‑running SAPIs (RoadRunner, Swoole, ReactPHP, PHP‑CLI loops) where one process serves many requests. Under FPM each worker handles a single request and exits, so there is no request loop to stop and no "finish current request, refuse new ones" phase for the runner to manage. Treat shutdown under FPM as an infrastructure concern, not a laminas concern.
Confirmed by design: the runner's graceful shutdown is opt‑in and requires pcntl. It registers handlers (typically SIGTERM/SIGINT) that set a flag the request loop checks between iterations. No loop, no benefit.
Likely, but verify on your stack: when FPM's master sends SIGTERM to a worker (reload, request_terminate_timeout, process_control_timeout expiry), whether your registered handler runs before exit depends on FPM version and pool settings. Do not rely on laminas handlers as an interception point here; assume the request is simply killed.
register_shutdown_function and a custom pcntl_signal handler, then send SIGTERM to a busy worker.connection_aborted() only reflects the abort after PHP attempts output (or the SAPI notices it). With default ignore_user_abort(false), PHP terminates the script on disconnect once a write occurs. There is no poll‑only mechanism.max_execution_time.php-fpm.conf: process_control_timeout, request_terminate_timeout, plus web server timeouts and max_execution_time.vendor/laminas/laminas-httphandlerrunner source to confirm which signals your version registers — this is version‑sensitive.One diagnostic that would change this recommendation: confirm whether pcntl is even enabled in your FPM build (php -m | grep pcntl). If it is absent, the runner's graceful shutdown path is dead code in your deployment regardless of SAPI.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.