Troubleshooting guide
PHP maximum execution time exceeded: how to fix it
A script ran past `max_execution_time`. Rather than raising it, ask why a web request needs that long.
3 min read10 sectionsUpdated
On this page
What it means
The script used up its allowed execution time, 30 seconds by default for web requests, while the CLI has no limit by default. On Linux, time spent in system calls, database queries and sleep() does not count, so a script hitting this limit is often really burning CPU. On Windows, the wall clock is used.
# PHP and FPM timeouts
php -i | grep max_execution_time
grep -rE 'request_terminate_timeout|request_slowlog_timeout' /etc/php/*/fpm/
# Nginx limits on the FastCGI side
sudo nginx -T 2>/dev/null | grep fastcgi_read_timeout
# Stack traces for slow requests
sudo tail -40 /var/log/php-fpm-slow.logFixes
Move long work into a queue with Laravel Queues, Symfony Messenger or a cron job. Process in batches with progress saved between them, so work can resume. Fix slow loops using profiling data. If an admin task truly needs longer, raise the limit for that route only with set_time_limit(120). Line up other timeouts accordingly. Show progress to the user for anything that remains long-running.
How the timeouts interact
Three settings apply. max_execution_time is enforced by PHP and produces this fatal error. request_terminate_timeout is enforced by FPM, and kills the worker with no PHP error, which shows up as a 502. fastcgi_read_timeout is enforced by Nginx, and gives the user a 504 while PHP may keep running. Since each has a different symptom, the error your users see tells you which limit fired first. Set fastcgi_read_timeout slightly longer than the PHP limit, so that errors surface in your application's logs with useful context.
Catch it automatically
PHP monitoring identifies the slowest endpoints before they reach the limit. Use a cron heartbeat for moved batch work, so that a stalled job alerts you.
How do I increase the limit?
Set max_execution_time in php.ini or use set_time_limit() for one script, if it is allowed.
Why does a slow query not trigger it?
On Linux, time spent waiting on external calls does not count.
Does it apply on the command line?
The CLI default is 0, meaning no limit.
Related reading
- GC overhead limit exceeded in Java: how to fix it: Fix java.lang.OutOfMemoryError: GC overhead limit exceeded. Enable GC logs, take a heap dump, find what fills the heap and size the JVM for containers.
- Nginx "no live upstreams": how to fix it: Fix Nginx no live upstreams while connecting to upstream: how max_fails marks servers down, why one failure can empty a pool, and how to configure it properly.
- MySQL "Lock wait timeout exceeded": how to fix it: Fix MySQL error 1205 Lock wait timeout exceeded: find the blocking transaction with the performance schema, shorten transactions and index your updates.
- JavaScript heap out of memory: how to fix it in Node.js: Fix FATAL ERROR: JavaScript heap out of memory. Set --max-old-space-size correctly, handle build-time failures and find runtime leaks with heap snapshots.
- 429 Too Many Requests: what it means and how to fix it: 429 Too Many Requests explained: rate limits, the Retry-After header, backoff with jitter for clients, and how to set fair rate limits on your own API.
- MySQL server has gone away: causes and how to fix it: Fix MySQL error 2006 server has gone away: idle timeouts, oversized packets, server restarts and connection pools holding connections that have died.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.