PHP set_time_limit() and PHP-FPM request_terminate_timeout: coordination for graceful termination
0 reputation · 07 Aug 2024, 22:21 UTC
PHP set_time_limit() and PHP-FPM request_terminate_timeout coordination
The goal is to allow a long‑running PHP script to clean up resources when either the internal execution limit or the FPM hard timeout is reached, without relying on external process management.
While set_time_limit() can reset or extend the CPU‑time limit tracked by PHP, the FPM setting request_terminate_timeout forces a worker kill after a wall‑clock interval, bypassing PHP’s signal handling. The interaction between these two limits is not explicitly defined in the documentation, leaving uncertainty about which timeout takes precedence and whether any cleanup code can execute after an FPM‑initiated termination.
- Does request_terminate_timeout interrupt execution before PHP’s internal timer expires, or does it only act after the PHP limit is reached?
- If both limits are active, can a script rely on register_shutdown_function or similar mechanisms to run when FPM kills the worker?
- Is there a reliable way to extend or disable request_terminate_timeout from within PHP to match the behavior of set_time_limit()?