If you have been using WordPress for a while I’m quite sure that you’ve encountered this PHP fatal error: “Maximum execution time of 30 seconds exceeded“. This is usually happening because PHP has a maximum time to execute a script, which usually defaults to 30 seconds. It is possible that some plugins need a longer execution time for certain tasks, for example creating a backup.
The Problem
The other day I was testing a backup plugin and it was crashing every time I was attempting to create a backup. In this case there wasn’t any message at all. It was simply failing without any explanation, so I abandoned it. I wasn’t very fond of it anyway.
Later I realized that the error was occurring during an Ajax call to the server behind the scenes, that’s why the error message wasn’t visible.
But today I was trying to update my OptimizePress templates and this time it kept displaying this error over and over again. It was now clear to me that I have to increase the execution time.
The Solutions
I’m quite sure that you’ve encountered a similar situation, but I have good news for you, I found a solution. In fact there are even three solutions.
1. Modify wp-config.php file.
Open wp-config.php file and add this line near the top but after <?php opening tag:
set_time_limit(300);
You can set any value. I used 300 seconds (5 min).
2. Modify .htaccess file.
Add this line in .htaccess:
php_value max_execution_time 300
This must be tested with your hosting. In my case, this didn’t work. I presume that my hosting doesn’t support php_value directives.
3. Modify php.ini file.
max_execution_time = 300;
This solution is only feasible if you have access to php.ini file, which is not the case on shared hosting.
In my case I used the solution #1 which was the only usable for me. After I made the change, the update succeeded.
PHP Resources
If you want to go beyond the subject of this article and learn more about PHP, here are some of the best websites to visit:
Leave a Reply