Skip to content
Diamond Sierra

Maximum execution time of 30 seconds exceeded

PHP stopped a request that ran longer than its time limit. The file in the message is where it stopped, not always the cause. Find the slow part before raising the limit.

Updated · By Diamond Sierra

On this page

This PHP fatal error means one request ran longer than the time PHP allows, so PHP stopped it partway through. Whatever the request was doing (saving a post, running an import, loading a page) did not finish. Raising the limit lets slow work finish. Finding the slow part makes the work fast.

PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /home/site/public_html/wp-content/plugins/example/includes/sync.php on line 88

What does the time limit count?

The limit is PHP's max_execution_time setting, often 30 seconds. On Linux servers it counts the time PHP itself spends working. Time spent waiting for the database, for another server, or for the disk is not counted. So when this error appears on a typical Linux host, PHP was busy: a long loop, resizing images, building a large export, or processing a big response. On Windows servers, waiting time counts too.

Is the file in the message the cause?

Not always. The file and line are where PHP happened to be when the clock ran out. If one plugin spent 28 seconds and another took the last 2, the second one is named. Treat the file as a clue. If the same file and line appear every time, that code is the likely cause; if they change, look for what uses the time earlier in the request.

How do I raise the maximum execution time?

WordPress has no wp-config.php setting for this; it is a PHP setting. Depending on your host, change it in the hosting control panel's PHP settings, or in a php.ini or .user.ini file in the site's root folder:

max_execution_time = 120

Some hosts cap it and ignore higher values. The web server or a proxy in front of it may also stop waiting first, which shows up as a 504 Gateway Timeout instead of this message. Ask your host which limit applies.

Should I raise it?

For a one-off job you start yourself, such as an import, a backup or a migration, a higher limit is reasonable. For ordinary page views, no. A visitor won't wait 30 seconds for a page, and every slow request holds a PHP worker and a database connection that other visitors need. A page that takes that long has a problem worth finding.

What usually takes this long?

  • Imports and exports of thousands of posts, products or orders in one request
  • Backups and migrations run from the browser
  • Regenerating or resizing images
  • Code that loops over every order or user instead of working in batches
  • Updating a large plugin on a slow disk
  • A loop that never ends

How do I run long jobs without hitting the limit?

Run them from the command line. WP-CLI uses PHP's command-line version, where the time limit is off by default, so wp commands for imports, search-replace and image regeneration don't time out. For work that has to run inside WordPress, plugins should split it into small background jobs (for example with Action Scheduler) instead of one long request.

How Paul Bunyan helps

Paul Bunyan records the fatal error itself (PB-2201) with the plugin, file and line, and records the requests that come close before they fail: slow requests (PB-2101), requests that use a lot of processor time (PB-2104), and the slow functions and hooks inside them (PB-2601, PB-2602). That tells you which plugin spends the time, not just where PHP stopped.