Fixing "Maximum execution time of 30 seconds exceeded" in WordPress
What the "Maximum execution time of 30 seconds exceeded" error means, what PHP's time limit really counts, where WordPress raises it, how to raise it safely and how to find the slow job behind it.
If you've seen a line like this on screen, in your debug log or in a WordPress recovery mode email, PHP has stopped a request because it ran out of time (the plugin name is made up):
PHP Fatal error: Maximum execution time of 30 seconds exceeded in /home/user/public_html/wp-content/plugins/example-backup/includes/class-archiver.php on line 214
PHP gives every request a time allowance, 30 seconds by default, and stops it dead when that runs out.1 Visitors usually see "There has been a critical error on this website" or a blank page.2 In the dashboard it looks like an update that stops halfway, an import that never finishes or a button that spins and then gives up.
It nearly always happens during heavy work such as an update, an import, a backup or a big WooCommerce report, or when a plugin gets stuck in a loop. Raising the limit gets a one-off job finished. Finding out why the job takes so long is what stops the error coming back.
Read the error message
"30 seconds" is the limit that was in force. It's PHP's default,1 so it usually means nobody has changed it. If you've raised the limit to 120 and the error still says 30, your change isn't being applied. 300 seconds during an update usually means WordPress's own five-minute allowance ran out (see below).
The file path is where PHP happened to be when the clock ran out, which isn't necessarily what used up the time. If a backup plugin spends 29 seconds compressing files and then hands over to WordPress to save a setting, the error points at WordPress's own files. Treat the path as a hint and check the log lines just before it. Our guide to reading an error line explains file paths.
A recovery mode email reads "An error of type E_ERROR was caused in line 214 of the file ... Error message: Maximum execution time of 30 seconds exceeded".3 WordPress picks which plugin or theme to blame purely from the file path,4 so the one named may only have been next in line. It only sends these emails for errors on admin screens, the login page and a few actions such as updating plugins,5 and only when the file is inside a plugin or theme folder, at most once a day.4 A timeout in a background job, on a public page or in WordPress's own files won't produce one.
If your host's logs show "30+2 seconds exceeded (terminated)", PHP got stuck while tidying up after the timeout and was force-stopped 2 seconds later.6 PHP writes that message straight to the server's error output, so it never reaches WordPress's debug log, and on PHP-FPM servers it may not be logged at all.78
Understand what PHP's time limit counts
max_execution_time is PHP's setting for how long a script may run. The PHP manual says it "helps prevent poorly written scripts from tying up the server". It's 30 seconds for web requests and 0, meaning no limit, when PHP runs from the command line, as WP-CLI does.1
What the clock measures surprises most people. In the manual's words:9
Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.
That's the behaviour on Linux and other non-Windows servers. PHP's clock only ticks while PHP itself is working, so waiting for the database, another site's API or a download doesn't count. When you see this error, PHP really did spend about 30 seconds of its own effort on the request: compressing, unzipping, resizing images, working through thousands of products or going round in a loop. By the clock on the wall it may have been running far longer.
The exceptions are Windows servers and thread-safe PHP builds from PHP 8.3 onwards, where the clock measures real elapsed time, waiting included.91
The flip side: a page that's slow because it's waiting, on a struggling external service or an overloaded database server, usually runs into a different timeout first. Raising max_execution_time won't help with that.
Rule out the timeouts that look similar
The other limits around PHP count real time, waiting included. WordPress's own documentation points out there's no sense giving PHP a long limit if the web server's is shorter, since the web server cuts the request off anyway.10
| Limit | Default | What you see when it runs out |
|---|---|---|
PHP max_execution_time |
30 seconds of PHP's own work1 | "Maximum execution time of 30 seconds exceeded" |
PHP-FPM request_terminate_timeout |
Off unless your host sets it11 | Usually a 502 on Nginx or a 503 on Apache, with nothing in WordPress's logs |
Web server (Nginx fastcgi_read_timeout, Apache TimeOut) |
60 seconds, though many hosts use 30012131 | Usually 504 Gateway Timeout (Nginx, or Apache with PHP-FPM) |
| Cloudflare | 125 seconds14 | Cloudflare error 524 |
| WordPress HTTP API (calls to other sites) | 5 seconds per request15 | An error such as cURL error 28 handed back to the plugin |
PHP-FPM's timeout is a backstop for when max_execution_time "does not stop script execution for some reason".11 When it fires, the PHP process is killed outright, so WordPress logs nothing. The host's PHP-FPM log gets a line ending "execution timed out (... sec), terminating".16
The web server timeout is how long the web server waits without hearing back from PHP.12 Only your host can change it, and Cloudflare only lets Enterprise plans raise its limit, up to 6,000 seconds.14 Our guide to 502, 503 and 504 errors covers tracking down the slow requests behind those.
The HTTP API limit applies to requests your site makes to other sites, such as licence checks and shipping rates. A call that runs out of time comes back as an error, usually cURL error 28 (curl's code for a timeout),17 rather than stopping the page.
See where WordPress raises the limit itself
WordPress has no time setting of its own, nothing like WP_MEMORY_LIMIT for memory. Instead, a few core tasks call set_time_limit(), which restarts PHP's clock with a new allowance:9
| Task | Time WordPress asks for |
|---|---|
| Installing or updating a plugin or theme, after the package is downloaded and unzipped | 300 seconds18 |
| Updating WordPress itself, while the new files are copied into place | 300 seconds19 |
| Automatic updates of active plugins, while it checks the site still loads | 10 minutes20 |
| Saving an active plugin or theme in the built-in file editor, while it checks for breakage | 5 minutes21 |
Apart from a few other small cases and bundled libraries, everything else gets your normal limit. That includes downloading and unzipping update packages, which happen before the extra time starts,18 along with Tools→ Export, image resizing on upload, saving in the block editor and WP-Cron tasks. Admin screens get no extra time, even though WordPress gives them extra memory.
Each of these calls checks that set_time_limit() is available first.18 If your host has switched it off or locked the setting,11 WordPress carries on with the normal limit. That's one reason the same update can work on one host and time out on another.
If it happened during an update
A timeout partway through an update can leave things half done, so check the site straight away:
- If visitors see "Briefly unavailable for scheduled maintenance. Check back in a minute.",22 follow our guide to getting WordPress out of maintenance mode.
- If the dashboard says "Another update is currently in progress.",23 see our guide to fixing "Another update is currently in progress".
- If a plugin has gone missing or the site shows a critical error, see recovering a site broken by an update.
If the error mentions 300 seconds, WordPress's own five minutes ran out, which points at a slow server or a very large package rather than PHP's setting. Once the site is working, take a fresh backup and try again at a quiet time, or run the update with WP-CLI (see below).
Check your current time limit
Go to Tools→ Site Health, click the Info tab and open the Server section. PHP time limit shows the limit in seconds for that page load, where 0 means no limit.24 If you can't get into the dashboard, your host's PHP settings page usually shows it too.
The same section shows PHP SAPI, which tells you how PHP runs on your server.24 That decides which of the methods below will work. apache2handler means PHP runs as an Apache module, litespeed means a LiteSpeed server and fpm-fcgi (PHP-FPM) or cgi-fcgi means PHP runs separately from the web server through FastCGI.25
Raise the time limit safely
For a genuine one-off job, such as a big import or a slow update, raising the limit is a fair fix. It's rarely the right fix for pages your visitors load, as how high to go explains.
Use your host's PHP settings
Most hosting control panels have a PHP settings page with a max_execution_time option. It's the safest route, because the host's own tools know how PHP runs on your server. If there isn't one, ask support: "I'm getting 'Maximum execution time of 30 seconds exceeded' on my WordPress site. Can you raise max_execution_time to 120 seconds, and is there a PHP-FPM or web server timeout lower than that?"
Edit php.ini or .user.ini
Some hosts let you set PHP options in a file in your site's main folder. Add this line, or edit the existing one if it's there:
max_execution_time = 120
.user.ini works where PHP runs through CGI/FastCGI (fpm-fcgi or cgi-fcgi), and PHP rereads it every five minutes by default, so give it a few minutes before testing.26 LiteSpeed servers read it too if the host has switched that on.27 Whether a php.ini in that folder is read at all depends on the host, so check their help pages first.
Use .htaccess only on Apache module or LiteSpeed servers
A php_value max_execution_time 120 line in .htaccess only works where PHP runs as an Apache module (apache2handler)28 or on LiteSpeed.29 On Apache without the PHP module it causes a 500 error across the whole site, and on Nginx servers it does nothing, because Nginx doesn't read .htaccess files. Save a copy of .htaccess first, put the line above # BEGIN WordPress (WordPress rewrites everything between its markers when permalinks are saved)30 and remove it straight away if the site breaks.
Add a line to wp-config.php as a last resort
If none of those are available, you can ask for more time from wp-config.php with the same function WordPress uses for updates. Only add it if PHP time limit in Site Health shows less than 120 seconds, because on a host that already allows more it would lower the limit (and 0 means no limit, so leave that alone). Download a copy of the file first, then add this just above the line that starts /* That's all, stop editing!:
if ( function_exists( 'set_time_limit' ) && 'cli' !== PHP_SAPI ) {
set_time_limit( 120 );
}
Both checks matter. Since PHP 8.0, a function the host has switched off doesn't exist at all,31 so a bare set_time_limit() call would crash the site with a "Call to undefined function" error. The second check leaves WP-CLI, which loads wp-config.php too,32 with its usual unlimited time.33
It can't beat a host that has locked the setting with php_admin_value, which PHP code can't override.11 If PHP time limit in Site Health hasn't changed, remove the line and ask your host.
How high to go
60 to 120 seconds suits most sites day to day. 300 seconds, the allowance WordPress gives its own updates, is reasonable while a one-off job runs. Put it back afterwards.
I wouldn't use 0 (no limit) on a live site. Without a limit, a request stuck in a loop keeps a PHP worker busy until something else kills it, and on smaller plans a few of those can leave visitors with 503 errors. For jobs you run in the browser, the web server's timeout and Cloudflare's 125 seconds still apply, so a PHP limit far above them rarely helps.
Find what is taking so long
Once the job has finished, work out why it needed so long. That's what stops the error coming back.
Check the logs
Turn on the debug log, repeat the job and search wp-content/debug.log for "Maximum execution time". Note the time and the path, and look at the lines just above for warnings from a particular plugin. If nobody was doing anything at that moment, suspect a scheduled task. On WooCommerce sites, also check WooCommerce→ Status→ Logs for the "fatal-errors" source, which is recorded even with debugging off.34 Switch debugging off and delete debug.log afterwards.
If the logs are empty but visitors got a 502 or 504, one of the other timeouts probably cut in first. Ask your host to check the web server and PHP-FPM logs for that time.
Measure it with Query Monitor
The free Query Monitor plugin's Overview panel shows how long a page took, with a line such as "45.0% of 30s limit".35 That figure is real time, waiting included, so it overstates what PHP's own clock saw. HTTP API Calls lists each request to other sites with its timeout and how long it took,36 and Slow Queries, under Database Queries, lists database queries that took over 0.05 seconds.37
It can't show the request that actually died, because it skips its output after a fatal error.38 Use it on a slow page that still loads, or on a smaller version of the job (a short import file, a narrower date range). Deactivate it when you've finished.
Test plugins one at a time
If the log points at a plugin, start there. Otherwise deactivate plugins one at a time under Plugins→ Installed Plugins, repeating the failed job after each. That switches features off for visitors too, so pick a quiet time or use a staging copy. The Health Check & Troubleshooting plugin's troubleshooting mode disables plugins for your session only,39 but it hasn't been updated since July 2024, so check it works on your site first. Take a backup all the same, note which plugins were active and switch them back on afterwards.
The usual suspects
- Backup plugins. Compressing a whole site is exactly the work PHP's clock counts. Look for settings that split the archive into parts or leave out caches and old backups, or rely on your host's own backups, which don't run through WordPress.
- Imports and exports. WooCommerce's own product CSV importer works in batches of 30 rows and cuts a batch short once it passes 20 seconds, precisely to avoid timeouts.40 Tools that do everything in one request are the ones that fall over. The WordPress Importer plugin tries to remove the time limit for its import step without first checking it's allowed to.41 If your host has locked the setting you'll still get a timeout, and if the host has switched the function off you'll see "Call to undefined function set_time_limit()" instead. WP-CLI's
wp importskips that step.42 - WooCommerce reports and bulk edits. Analytics over long date ranges and bulk edits of hundreds of products. Try shorter ranges or smaller batches.
- Scheduled tasks. Errors at regular times, or when nobody was on the site, point to WP-Cron. Action Scheduler, which WooCommerce uses for background jobs, stops picking up new tasks when a run looks likely to pass 30 seconds,43 so a timeout there usually means one task is doing too much. See our guide to failed scheduled actions.
- A bloated database. Waiting for the database doesn't count, but PHP still has to work through whatever comes back, and huge sets of autoloaded settings make every request heavier. Site Health warns "Autoloaded options could affect performance" past about 800 KB,44 and our slow admin dashboard guide covers the clean-up.
- Images. Regenerating thumbnails and image optimisation plugins make PHP work hard. Our guide to media upload errors covers uploads.
- A loop after an update. If the error started straight after an update and keeps happening however high the limit, the code is probably going round in circles. Roll the update back and report it to the developer.
Time and memory errors often turn up on the same heavy jobs. If the whole site is sluggish rather than one job, see diagnosing a suddenly slow WordPress site.
Run long jobs with WP-CLI instead
If your hosting includes SSH access, WP-CLI is often the best way to run big jobs. PHP's command-line version has no time limit by default, and php.ini can't change that,33 though WordPress and some plugins still set their own limit, such as 300 seconds for updates.18 Nor does the job pass through the web server or Cloudflare, so their timeouts don't apply.
| Job that times out in the browser | WP-CLI command |
|---|---|
| Importing a WordPress export file | wp import export.xml --authors=create (needs the WordPress Importer plugin)45 |
| Exporting content | wp export46 |
| Regenerating thumbnails | wp media regenerate --only-missing47 |
| Running overdue scheduled tasks | wp cron event run --due-now48 |
| Clearing an Action Scheduler backlog | wp action-scheduler run49 |
| Updating a plugin or WordPress | wp plugin update plugin-name or wp core update5051 |
Imports, thumbnail regeneration and updates all change your site, so take a backup before running them, just as you would in the browser. wp cron event run --due-now and wp action-scheduler run fire every pending job at once, which can mean a burst of emails, syncs or webhooks, so check what's queued first. And plain wp media regenerate deletes the old thumbnail files unless you add --skip-delete, which is why the table uses --only-missing (it only fills in missing sizes and leaves existing files alone).47
Common questions
Is a 300-second time limit safe?
For one-off jobs, yes. WordPress gives its own updates 300 seconds.18 As a permanent setting on a busy site it's less sensible, because a stuck request can then hold one of your PHP workers for five minutes before anything stops it, and other visitors queue behind it. I'd keep 60 to 120 seconds day to day and raise it only while a big job runs.
Will raising the time limit slow my site down?
No, not by itself. The limit is a ceiling, so a page that takes two seconds still takes two seconds. The risk is indirect: a higher limit lets slow or stuck requests run for longer, and on small hosting plans a few of those at once can use up the server's PHP workers and cause 503 errors for everyone else.
Why does it only happen in the admin or during imports?
Because that's where the heavy work happens. Imports, exports, backups, updates and big reports do minutes of processing in a single request, while most visitor pages are small and often cached. WordPress gives admin screens no extra time, unlike memory, so a plugin that doesn't split its work into batches runs into the same 30 seconds as everything else.
What can I do if my host won't raise the time limit?
Make the job smaller or run it another way. Split imports into smaller files, export shorter date ranges and look for a batch or background processing option in the plugin's settings. If your plan includes SSH, run the job with WP-CLI, which has no time limit by default. If the host's limits keep getting in the way of normal work, a bigger plan may be due.
Still timing out?
If you've raised the limit and the job still won't finish, or you can't tell which plugin is behind it, my emergency WordPress support can track it down and get the job done. Many fixes are £50 all in and you'll get a fixed quote before I start. No fix, no fee. My maintenance plans include updates tested on a staging copy first, uptime monitoring and monthly performance checks, which catch slow jobs and failing updates early.
Runtime configuration (max_execution_time), PHP Manual. ↩ ↩ ↩ ↩ ↩ ↩
class-wp-fatal-error-handler.php (display_default_error_template), WordPress source code on GitHub. ↩
error-protection.php (wp_get_extension_error_description), WordPress source code on GitHub. ↩
class-wp-recovery-mode.php (handle_error, get_extension_for_error, get_email_rate_limit), WordPress source code on GitHub. ↩ ↩
load.php (is_protected_endpoint, is_protected_ajax_action), WordPress source code on GitHub. ↩
Description of core php.ini directives (hard_timeout), PHP Manual. ↩
zend_execute_API.c (zend_timeout_handler), PHP source code on GitHub. ↩
FPM configuration (catch_workers_output), PHP Manual. ↩
set_time_limit, PHP Manual. ↩ ↩ ↩
PHP Optimization (Timeouts), WordPress Advanced Administration Handbook. ↩
FPM configuration (request_terminate_timeout, php_admin_value), PHP Manual. ↩ ↩ ↩ ↩
Module ngx_http_fastcgi_module (fastcgi_read_timeout), nginx documentation. ↩ ↩
Apache core features (TimeOut directive), Apache HTTP Server documentation. ↩
class-wp-http.php (http_request_timeout), WordPress source code on GitHub. ↩
fpm_request.c (fpm_request_check_timed_out), PHP source code on GitHub. ↩
libcurl error codes (CURLE_OPERATION_TIMEDOUT), curl documentation. ↩
class-wp-upgrader.php (install_package), WordPress source code on GitHub. ↩ ↩ ↩ ↩ ↩
update-core.php (update_core), WordPress source code on GitHub. ↩
class-wp-automatic-updater.php (update), WordPress source code on GitHub. ↩
file.php (wp_edit_theme_plugin_file), WordPress source code on GitHub. ↩
load.php (wp_maintenance), WordPress source code on GitHub. ↩
class-core-upgrader.php, WordPress source code on GitHub. ↩
class-wp-debug-data.php (get_wp_server), WordPress source code on GitHub. ↩ ↩
php_sapi_name, PHP Manual. ↩
.user.ini files, PHP Manual. ↩
LSPHP Options (LSPHP_ENABLE_USER_INI), LiteSpeed Documentation. ↩
How to change configuration settings, PHP Manual. ↩
cPanel tuning: Disable PHP Override, LiteSpeed Documentation. ↩
misc.php (insert_with_markers), WordPress source code on GitHub. ↩
Description of core php.ini directives (disable_functions), PHP Manual. ↩
Runner.php (load_wordpress), WP-CLI source code on GitHub. ↩
Differences between the CLI SAPI and other SAPIs, PHP Manual. ↩ ↩
class-woocommerce.php (log_errors), WooCommerce source code on GitHub. ↩
Query Monitor (overview panel), Query Monitor source code on GitHub. ↩
Query Monitor (HTTP API Calls panel), Query Monitor source code on GitHub. ↩
Query Monitor (database queries collector), Query Monitor source code on GitHub. ↩
Query Monitor (Dispatcher.php, should_dispatch), Query Monitor source code on GitHub. ↩
Health Check & Troubleshooting, WordPress.org Plugin Directory. ↩
class-wc-product-csv-importer-controller.php and abstract-wc-product-importer.php (time_exceeded), WooCommerce source code on GitHub. ↩
class-wp-import.php (dispatch), WordPress Importer source code on GitHub. ↩
Import_Command.php, WP-CLI source code on GitHub. ↩
ActionScheduler_Abstract_QueueRunner.php (get_time_limit), Action Scheduler source code on GitHub. ↩
class-wp-site-health.php (get_test_autoloaded_options), WordPress source code on GitHub. ↩
wp media regenerate, WP-CLI Commands. ↩ ↩
wp cron event run, WP-CLI Commands. ↩
wp plugin update, WP-CLI Commands. ↩
wp core update, WP-CLI Commands. ↩