PHP error guide
PHP "Maximum execution time exceeded": Causes and Fixes
Error summary
The script ran longer than `max_execution_time`. Optimize the hot loop, move work to a queue/CLI job, or raise the limit for that specific long-running task.
What it means
The script ran longer than max_execution_time. Optimize the hot loop, move work to a queue/CLI job, or raise the limit for that specific long-running task.
What the error means
PHP’s execution timer aborted the request after the configured number of seconds (0 means unlimited on many builds).
Why PHP produces it
Web SAPIs use time limits to protect workers from stuck requests. External HTTP calls, huge imports, and accidental infinite loops are typical triggers.
PHP version notes
set_time_limit() / max_execution_time interact with OS signals; FPM terminate timeouts may still win.
Most common causes
- Slow remote HTTP/DB calls without timeouts
- Large synchronous imports in a web request
- Infinite or near-infinite loops
- Low
max_execution_timeon shared hosting
Minimal examples
BAD — reproduces the problem
while (true) {\n // accidental infinite loop\n}
FIXED — safer pattern
set_time_limit(120); // for a known batch boundary\nforeach ($batches as $batch) {\n process_batch($batch);\n}
Step-by-step diagnosis
- Note the seconds value in the fatal message.
- Identify the line—often inside a loop or remote call.
- Check FPM
request_terminate_timeoutwhich can kill workers independently. - Compare web vs CLI limits.
Fixes
Fix #1: Move heavy work off the request
Use a queue/cron/CLI worker for imports and reports.
php bin/console app:import --file=data.csv
Fix #2: Set timeouts on I/O
Ensure cURL/DB calls cannot hang forever.
curl_setopt($ch, CURLOPT_TIMEOUT, 10);\ncurl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
Common mistakes when fixing it
- Blindly setting
max_execution_time=0on public FPM pools
How to prevent it
- Async jobs for long tasks
- Hard timeouts on outbound HTTP
Web server / environment notes
Web pools vs CLI cron jobs need different budgets
Tags: fpm,apache,nginx,cli,cron,shared-hosting