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:
1 |
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:
1 |
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.
1 |
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.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.