Skip to content

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

Key points

  • On Linux, the limit counts script time, not waiting.
  • Several timeouts apply at once.
  • Long work belongs in a queue.
  • The line named is just where time ran out.

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.

Common causes

  • Large loops over data.
  • Imports and exports run within a web request.
  • Heavy image handling.
  • Infinite loops.
  • WordPress plugin or theme updates on slow hosting.

Diagnose it

Find the configured values for all layers, and turn on the FPM slow log.

bash
# 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.log

Fixes

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.

Frequently asked questions

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.

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.