ThisCalculator

Everyday

WordPress PHP Time Limit: Fix Maximum Execution Exceeded

Updated · Standard formula, shown below

WordPress PHP Time Limit: Fix Maximum Execution Exceeded

If WordPress shows a “Maximum execution time of 30 seconds exceeded� error, the fix is to increase the PHP time limit in your site’s configuration. You can do this by editing the wp-config.php file, adding a line to .htaccess, or updating the php.ini file, depending on your hosting environment.

What the Error Means

PHP has a built-in safety limit that stops a script if it runs too long. This prevents a single request from hanging the server forever. When a plugin, theme, or core update takes longer than the limit, you see the “Maximum execution time exceeded� fatal error. The default limit is often 30 seconds, but some hosts set it lower (like 20 seconds) or higher (like 60 seconds).

The error is not a bug in WordPress itself—it’s a resource limit that your server enforces. It can happen during a large import, a heavy cron job, a backup, or when a plugin performs a lot of database work.

How PHP Time Limits Work

PHP’s max_execution_time directive controls how long a single script may run. It counts CPU time, not wall-clock time, on most Unix-like systems. That means if your script waits for a slow external API, the clock may not tick—but on Windows or with certain configurations, it can count real time.

The limit is set in php.ini, but it can be overridden in several places: at the server level, in a virtual host, in .htaccess, or directly in the PHP script using set_time_limit(). WordPress itself calls set_time_limit() in some places, but not everywhere.

How to Increase the Time Limit (Step-by-Step)

Try these methods in order. Start with the easiest one that works for your setup.

  1. Edit wp-config.php – Add this line near the top, after the database settings:
    set_time_limit(300);
    This sets the limit to 300 seconds (5 minutes) for all WordPress requests.
  2. Edit .htaccess – Add this to the top of your .htaccess file:
    php_value max_execution_time 300
    This only works if your host allows php_value in .htaccess (common on Apache with mod_php).
  3. Edit php.ini – If you have access to php.ini, find the line max_execution_time and change it to 300 (or whatever you need).
  4. Use a plugin – Some caching or performance plugins let you set PHP time limits from the dashboard. This is the easiest if you don’t want to edit files.

After making a change, test a page that previously failed. If it still errors, the limit might be set elsewhere or your host may restrict it.

Choosing the Right Time Limit

There’s no one-size-fits-all number. A good starting point is 120 seconds (2 minutes), which handles most imports and updates. For heavy operations like media imports or large backups, you might need 300 seconds (5 minutes) or more.

Consider these factors:

  • What operation is failing? A simple page load should never need more than 30 seconds—if it does, there’s likely a performance problem.
  • How large are your files? Importing a 100MB CSV will take longer than a 1MB one.
  • What does your host allow? Some shared hosts hard-code a maximum (like 120 seconds) and ignore your attempts to raise it.

Don’t set it to an absurdly high number like 3600 unless you have a specific reason. A runaway script could tie up server resources.

Common Problems and Misconceptions

One common misconception is that the error always means you need a higher limit. Often, it’s a symptom of a slow query or a plugin bug. Before increasing the limit, try disabling plugins and switching to a default theme to see if the error goes away.

Another issue: editing wp-config.php with set_time_limit() works only for the main request. If the error happens during a WordPress cron job, the cron may run in a separate process that doesn’t inherit that setting. In that case, you may need to increase the limit in php.ini or use a plugin that handles cron differently.

Also, note that max_execution_time does not affect all operations. For example, if a script is waiting for a slow network response, the time may not count toward the limit on Linux. So you might still see timeouts even with a high limit.

Alternatives to Increasing the Limit

If you can’t change the limit (or don’t want to), you can work around the error:

  • Optimize the slow operation – Use a caching plugin, optimize your database, or split large imports into smaller chunks.
  • Run heavy tasks via WP-CLI – Command-line PHP often has no time limit, so you can run imports or updates from the terminal.
  • Use a maintenance plugin – Some backup plugins let you schedule tasks that run in the background, avoiding the limit.
  • Ask your host – Many hosts will raise the limit for you if you explain why you need it.

Safety and Hosting Considerations

Before changing any server configuration, make a backup of the files you edit. A typo in .htaccess can cause a 500 error, and an incorrect php.ini line can break PHP entirely.

On shared hosting, you may not have access to php.ini. If .htaccess doesn’t work either, you can use ini_set() in a plugin file or in wp-config.php. However, some hosts disable ini_set() for security reasons.

Remember that raising the time limit is not a security fix. It doesn’t make your site more vulnerable, but it does allow a compromised script to run longer. Keep your plugins and themes updated and use strong passwords.

Frequently Asked Questions

What is the default PHP time limit in WordPress?

WordPress itself doesn’t set a default; the default comes from your server’s PHP configuration. Most often it’s 30 seconds, but it can vary by host. You can check your site’s phpinfo() or a plugin like “Server Info� to see the current value.

Can I increase the time limit without accessing php.ini?

Yes. You can add set_time_limit(300); to your wp-config.php file, or add a php_value directive to .htaccess if your host allows it. Some hosts also let you change PHP settings from the control panel (like cPanel’s “Select PHP Version� or “MultiPHP INI Editor�).

Why does the error still appear after I increased the limit?

Possible reasons: the setting is overridden elsewhere, your host caps the limit, the script is hitting a different limit (like memory limit), or the operation is genuinely taking too long. Check the error message for the exact limit mentioned—it may be a different value than what you set.

Is it safe to set the time limit to 0 (unlimited)?

Setting max_execution_time to 0 disables the limit entirely. It’s not recommended on a live site because a script with an infinite loop could hang your server. Use a finite number like 300 or 600 instead.

Does this error affect my site’s visitors?

Usually not directly. The error appears when a script runs too long, and it only affects that specific request. If it happens during a page load, visitors may see a blank page or an error message. But it’s often triggered by admin actions like imports or updates, which only you see.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.