PHP max execution time: How to increase
Sometimes you might have noticed that certain PHP scripts that you wrote are not working as desired. A very common error message is Fatal error: Maximum execution time of 30 seconds exceeded. The cause is the PHP restriction on the directive max_execution_time. But, it’s easy to adjust the PHP max execution time.
Firstly, the amount of time (in seconds) a PHP script is allowed to run is defined by the PHP variable max_execution_time. In most shared servers, the default configuration is 30 seconds. So, this article explains how a customer can modify the value of this variable if they need their PHP scripts to run for longer. We recommend not setting it very high.
How to solve Fatal error: Maximum execution time of 30 seconds exceeded
Firstly, log in to your cPanel account using your cPanel username and password. But, if you forgot the password, you can reset it any time using the ‘Reset Password’ option under the login box.
Once logged in and you are in the cPanel dashboard, go to Software -> Select PHP Version option.
It will take you to a page which lets you choose the version of PHP you would like to run along with the extensions you would like to enable or disable. Basically, to the top right of the page, there is another option ‘Switch to PHP Options’. Click on it.
Now, you will see a list of PHP variables along with the values associated with each variable. Check the value of max_execution_time, mostly it will be the default 30. Click on it and you can enter the new value you require. Suppose, I need to increase the value to be raised to 60 seconds (1 minute). I will enter 60 in the box and hit ‘Apply’. Scroll to the bottom and click on the ‘Save’ button for the changes to get into effect. This way, you will have a better PHP max execution time setting.
To confirm the changes, I will upload a file, say named info.php, to the public_html folder of my domain copablog.com. That is, such file must have the following contents in it:
Validating the change to PHP max execution time
Now take a browser and try accessing the file as http://copablog.com/info.php. Remember to change copablog.com to the domain name you are using. Search for max_execution_time in the page displayed and check the value listed. I can see that it has changed to 60 seconds.
At this point, your max_execution_time is changed to 60 seconds. Now, your PHP scripts can run for 1 minute without interruption now. This is the correct fix for the PHP max execution time issue.
Finally, you can read more about the PHP max execution time parameter here: http://php.net/manual/en/function.set-time-limit.php