Last updated on December 13, 2015
Today I would like to show you increasing PHP script execution time limit using ini_set()
function. PHP default script execution limit is 30 seconds.
In my recent project to prevent the script from timing out, I had to set the PHP script execution time directly from with in the php file. So to execute my script more then 30 second I added below shown line at top of my file(first line).
This will set to 5 minutes time limit:
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
set_time_limit()
has advantage, you can call it several times and it adds the time to the total script run-time. so you can use it in a loop and it doesn’t matter how many iterations you have, you set only the time per iteration.
The function set_time_limit(seconds)
does exactly the same. If seconds is set to zero, no time limit is imposed.
This will set to no time limit:
set_time_limit(0); //no limit
If you have access to your php.ini
file you can also configure execution time by changing following to something suitable to your requirement.
max_execution_time = 30
It is important to be careful using this on a production server. If you allow a script to run too long you could use all your servers resources and your website may go down.