PHP max_execution_time limits during blocking system calls
25.5K reputation · 16 Mar 2025, 00:28 UTC
The max_execution_time directive is designed to prevent scripts from running indefinitely by terminating execution once a specific time threshold is reached. However, the engine's timer behavior varies based on the type of operation being performed.
On Linux and Unix-based systems, the timer tracks CPU time. This means that while heavy mathematical computations trigger the timeout, certain blocking operations—such as stream reads, database queries, or sleep() calls—do not increment the execution timer. This creates a scenario where a script may exceed the configured max_execution_time if it spends the majority of its lifecycle waiting on external I/O.
When designing long-running processes or API integrations, it is unclear how to enforce a strict wall-clock timeout that accounts for both CPU processing and external blocking calls within a single execution thread.
- Does PHP provide a native mechanism to include system call duration in the
max_execution_timecalculation? - What is the recommended approach for implementing a global wall-clock timeout in web SAPI environments where
pcntl_alarmis unavailable?