Modify maximum execution time of a PHP script
June 6th, 2006I have written a PHP code to do some processing on data, but before the processing can finish, the script throws an error ‘Fatal error: Maximum execution time of 30 seconds exceeded in /home/dales/public_html/processbulkdata.php’.
- Dale
To change the maximum execution time of a PHP script you need to use the ‘set_time_limit‘ function. The function takes one argument which is the maximum number of seconds a script is allowed to run. If seconds is set to ‘0′, no time limit is imposed on the script and it may run indefinitely. Use the following snippet just before your time consuming code begins:
Note that, if you set the number of seconds to a value very high, you may recieve the fatal error just after 1 second. Its better to use ‘set_time_limit(0)‘ instead. Also, remember that when you are finished with the portion that performs the busy computation, its a good idea to call:
so that the remaining portion of the script finishes in 30 seconds or fatal error is thrown.
May 21st, 2007 at 8:37 pm
this tip is great..
i have a video website which load video and pass it to browser by php.. an it some time take more that 30s ..
now i can change the time to 60s which make sure all run better..
thanks for tips.
– this used here
http://www.mtvvui.com/videodownloader.php
December 16th, 2007 at 9:53 am
Great PHP tips thanks
September 11th, 2008 at 1:04 pm
Really helpful. thank you!
September 18th, 2008 at 1:27 pm
Great tip. Thanks!
I will need this for some PHP cron stuff I’m currently working on.
January 20th, 2009 at 6:46 am
where should i write “set_time_limit(0)”
for the error “Maximum execution time of 30 seconds exceeded in /home/data/users/m/mmm/m1/classes/http.php on line 427″