WordPress being a powerful and versatile platform also means that it is prone to all kinds of errors. One particular error we will be talking about in this article is the “Maximum execution time exceeded” error.
This error is nothing unfamiliar but is instead something pretty common that can occur in situations like updating themes, plugins, WordPress core files, and so on.
Your site ran into the maximum #ExecutionTime exceeded #Error? Here's how you fix it! Share on XWhen it does occur, it is pretty clear to see, since the debug.log file will display a message something along the lines of: Fatal error: Maximum execution time of 5 seconds exceeded.
What caused the error
For all of you belonging to the non-technical bunch, here’s a simplified explanation of how WordPress functions.
When you initialize an update or some other type of action in WordPress, the platform runs scripts that do various things such as change the database records and so on.
The execution time of these scripts is limited and if a script for whatever reason takes too long to execute, it will cause the error that is the focus of this article. Why you may ask?
Well, this is just one way how hosting companies protect their servers from resource abuse. Setting a limit on the execution time of a script allows the cancellation of a PHP process that hasn’t finished in time.
And while this is without a doubt a necessity, unfortunately, it can happen quite often even while doing actions that aren’t that complicated to execute like installing a plugin, updating it, or even when handling a WordPress theme.
It is important to note, that one of the most common situations in which you will deal with this error is when switching between web hosts solely for the reason that every web host has the liberty to define the length of the execution time allowed on their server.
In most cases, and with most hosting providers the time limit is set to 30 seconds, but that might not necessarily be enough for each of your PHP scripts to run causing the maximum execution time error to occur.
One unfortunate thing about this error is that it is not fixable with the use of a backup like many other WordPress errors. But luckily, there are plenty of methods you can use instead.
So let’s get straight to exploring what they are!
Methods of resolving the error
Just by reading the name of the error, one solution is pretty evident and that is increasing the script execution time limit.
But before we get into any explanations, we have to say that before making any changes to your site or its files, you should create a backup, just in case things go south and you need to get to where you started from quickly and easily.
Find the script that is taking too long to execute and remove it.
When we said that this error is caused by scripts that are taking too long to execute, we were mostly referring to scripts that do not belong to the WordPress core, instead, scripts that belong to the various themes and plugins you enrich your site with.
Why these scripts specifically? Well, WordPress core scripts are coded in accordance with many standards, while non-core scripts aren’t.
So before increasing your script execution limit using any of the methods we will list below, you should first try to find the scripts that are taking too long to execute.
If you’re a beginner in WordPress and coding in general, the culprit could very likely be one of your own scripts since beginners often tend to write oversimplified scripts that are not so efficient and just require too much time.
Edit the .htaccess file
Editing your .htaccess file is a very efficient method of resolving this error and one that is used very often. But since it is a bit of a delicate task to complete, for this one we especially recommend you create a backup of your site, just in case something goes wrong.
After you have taken that precautionary measure, you can then take your FTP client of choice, connect to it, and navigate to the root file of your WordPress directory usually labeled as pulic_html.
In the directory, look for the .htaccess file, right-click on it and select the View/Edit option.
Next, in the opened file, add this code to the very bottom: php_value max_execution_time 300.
This piece of code will increase the execution time to 300 seconds or in other words, 5 minutes.
Lastly, save the file and upload it to your server so that it can overwrite the old version.
Disable plugins and themes
There are situations in which increasing the execution time won’t help. Those situations are a strong indicator that the error was caused by a faulty theme or plugin.
Luckily, deactivating plugins isn’t a tough task to handle especially if you decide to use a plugin to help you out with that. Our recommendation would be the WP Reset plugin.
WP Reset is the perfect solution for giving your whole site (or just parts of it) a fresh start. Why you may ask? Well WP Reset comes with a multitude of tools and options that will wipe your site clean.
For instance, you could use the so-called nuclear reset which will remove everything except the core files or you could use one of the partial resets to get rid of content, themes, users, and of course plugins.
Meaning that if you decide on using WP Reset, you will have the option to disable all your plugins and thus remove the maximum execution time exceeded error in just a click!
Even if you can’t access the admin dashboard, but have the link for the Emergency Recovery Script which you will be provided with by the plugin, you can still remove all your plugins individually or in bulk.
After you have disabled all your plugins with or without WP Reset, you can start activating them one by one and single out the plugin that contains the time-consuming script which is causing the error.
If a plugin wasn’t the culprit, there’s a chance your current theme might be, in most cases, due to a plugin-theme conflict.
To resolve this, simply switch your theme for a default WordPress one, and you should be all good.
Use a plugin
The previously-explained method of editing the .htaccess file manually is an effective one but it can be a bit confusing and tiring.
So for all of you that like taking care of things automatically, we have good news, you can do the same using a plugin.
The plugin in question is the WP Maximum Execution Time Exceeded plugin which you just have to install, activate, and let it do its magic.
And although we like to call it that, what this plugin does is not magic, instead it’s just adding a configuration to your .htaccess file. And this particular configuration will simply cause an increase in your script execution time.
So to recap. Go into your WordPress dashboard, then the Plugins tab, and click on Add New.
Next, find the plugin by typing in its name in the search bar and then install and activate it.
After the plugin has been activated, it will do the rest of the work on its own and will extend the execution time to 5 minutes. This will give you enough time to run all kinds of scripts, properly-coded ones, that is.
Ask your hosting provider for assistance
For some of you, it might happen that you have tried all of the suggested methods and none of them seem to work.
We know that might feel like a dead-end situation, but it doesn’t have to be. You still have one thing you can do and that is reaching out to your hosting provider.
When reaching out to your hosting provider you have to ask them one simple question that question being if they can increase your “max_execution_time” value.
If that is something they can and are willing to do, then all you have to do is just sit back and wait until they take care of it. After that, you can go and freely execute your PHP scripts.
Conclusion
The maximum execution time exceeded error is nothing to be afraid of, instead it’s something that every WordPress user will have to deal with eventually.
Regardless if you are facing the error now or read this article in order to prepare for the worst-case scenario, the methods we listed in this article will without a doubt be helpful.
If anything was left unsaid or wasn’t explained clearly enough for you, please feel free to leave a question in the comments below. We will do our best to give you an answer as quickly as possible.
Comments are closed.