set_time_limit()
The default time limit of how long a script can run is set in the php.ini file with max_execution_time. If that is not set, the default is 30 seconds.
Sometimes we want to change this to accommodate longer running scripts or perhaps force a particular script to stop running before the default time limit. For this we use set_time_limit() and pass the number of seconds allowed. The timer starts from zero at the time this function is called.
<?php /* some code that runs for 5 seconds */ set_time_limit(15); /* more code that runs for 10 seconds */ set_time_limit(18); /* more code that runs for 5 seconds */ // total time: 20 seconds, and could still run for // another 13 since 18 was the last limit set and // it went for 5 seconds after that (18 - 5 = 13).
Get rid of the time limit with set_time_limit(0); though keep in mind that the http connection will timeout at some point.
A time limit is a good thing. If you’ve accidentally created an infinite loop, you don’t want it to go on forever.
