Skip to content
01

WordPress “Maximum execution time exceeded” error: a lasting fix

Raising max_execution_time makes the message go away, not the problem. Here is how to find what slows the script down, choose the right limit and fix the cause.

Walid Sadfi
4 min reading
Share:

The exact message looks like Fatal error: Maximum execution time of 30 seconds exceeded in /path/to/some-file.php on line 123. PHP stopped a script that ran longer than the max_execution_time setting allows. It shows up during an import, a backup, an update or on a page calling an external service. The temptation is to raise the limit and move on: sometimes necessary, rarely enough.

What the message tells you

The file quoted is where PHP happened to be when time ran out, not necessarily the culprit. If it is a wp-includes file related to HTTP requests, the script was waiting for an external service. If it is a database file, a query was too heavy. If it is a plugin file, look at that plugin first.

Do not confuse it with server timeouts

  • A 504 error comes from the web server, for instance Nginx with fastcgi_read_timeout, giving up before PHP does.
  • A 524 error comes from Cloudflare, which cuts any response longer than 100 seconds on most plans.
  • Raising max_execution_time is useless if one of these two limits hits first.

Step 1: find what is slow

Install the Query Monitor plugin on a staging copy: it shows slow SQL queries, outgoing HTTP calls and their duration, and the plugin behind each one. In the vast majority of cases, you find one of these four causes:

  • a call to an external service that does not answer, with no maximum timeout set;
  • an import or export processing thousands of rows in a single request;
  • a SQL query without an index on a large table, often wp_postmeta;
  • wp-cron scheduled tasks running during a visitor's page load.

Step 2: raise the limit in the right place

For a legitimately long task, raise the limit where your host reads it. The most reliable place is the PHP configuration, in php.ini or in your host's control panel:

max_execution_time = 120

On an Apache server with mod_php, the same value can go in .htaccess. Avoid set_time_limit() in wp-config.php however: many hosts ignore it, and it raises the limit for the whole site. Keep set_time_limit() for the start of a specific task you know to be long.

php_value max_execution_time 120

Step 3: fix the cause

Set a maximum timeout on external calls

A third-party service going down must never block your site. Set a short timeout on every HTTP call:

$response = wp_remote_get( $url, array( 'timeout' => 10 ) );

Move heavy tasks to the command line or to batches

WP-CLI has no execution time limit by default: run imports, thumbnail regeneration and migrations from the command line. For tasks triggered from the site, split them into small batches with Action Scheduler, the task queue used by WooCommerce.

wp media regenerate --only-missing
wp import file.xml --authors=skip

Take wp-cron out of page visits

By default, wp-cron runs during a visitor's page load. Disable that trigger and hand it to a real server scheduled task, every five minutes:

define( 'DISABLE_WP_CRON', true );

*/5 * * * * wp cron event run --due-now --path=/var/www/html

Frequently asked questions

Which value should max_execution_time have?

30 to 60 seconds are enough for a healthy site. Beyond 120 seconds, a task belongs on the command line or in a task queue, not in a web page.

The error only appears during updates, is it serious?

An interrupted update can leave a plugin or WordPress half installed. Run it again from the command line with WP-CLI, then check file integrity. Our WordPress maintenance service runs these updates on staging before applying them.

Need a developer to fix the problem or keep it from coming back? Discover our WordPress maintenance service.

Author

Walid Sadfi

Walid Sadfi is the founder of Evolurise, a team of engineers deployed on site with its clients: custom development (WordPress, Drupal, React, Laravel), AI agents, DevOps and team training. With 8 years of experience, he supports SMEs and large companies, from understanding the problem to deploying the solution. On this blog he shares practical, field-tested insights.