Common causes
- A slow or unindexed database query
- Polling or retrying a remote HTTP or API call in a loop without its own timeout
- Large imports, exports, backups or image processing run inside a web request
- An infinite or very long loop
- max_execution_time set too low for a legitimate admin task such as a plugin update
How to fix it
- Check the file and line. The path in the message shows where PHP was when time ran out, which is usually inside the slow operation. A line in a cURL or database class points to a slow remote call or query.
- Raise max_execution_time. Set max_execution_time = 120 in the active php.ini (find it with php --ini) and restart PHP-FPM. On Apache with mod_php you can use php_value max_execution_time 120 in .htaccess; on shared hosting use .user.ini or the control panel.
- Raise web server timeouts to match. If PHP now runs longer, Nginx may return 504 first. Raise fastcgi_read_timeout 120s; in Nginx, and request_terminate_timeout in the PHP-FPM pool if it is set lower.
- Extend the limit for one script. Call set_time_limit(300); at the top of a known long-running script. Each call restarts the timer, so calling it inside a batch loop keeps the job alive between batches.
- Run long jobs from the CLI. The PHP CLI has no execution time limit by default (max_execution_time = 0). Move imports, exports and bulk updates to a cron job or queue worker, for example php artisan queue:work or wp cli commands.
- Fix the slow part. Add indexes for slow queries (check with EXPLAIN), set timeouts on HTTP clients such as CURLOPT_TIMEOUT, and process large datasets in batches.
php.ini and Nginx
; php.ini
max_execution_time = 120
# Nginx location ~ \.php$ block
fastcgi_read_timeout 120s;
// one script only
set_time_limit(300); How to stop it happening again
- Set explicit timeouts on every outbound HTTP and API call
- Run imports, backups and reports from cron or a queue, not a browser request
- Index columns used in WHERE, JOIN and ORDER BY clauses
- Log slow requests with the PHP-FPM slowlog to catch problems early