How can we increase the execution time of a PHP script?

• Default time allowed to execute for PHP scripts is 30 seconds mentioned in the php.ini file. The function used to set execution time is set_time_limit(int sec). If the value passed is ‘0’, it takes unlimited time. It should be noted that if the default timer is set to 30 sec, and 20 sec is specified in set_time_limit(), the script will run for 45 seconds.
• This time can be increased by modifying the max_execution_time in secs in php.ini file. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.
example:

<?php 
set_time_limit(120); //// execution time is set to 2 minutes
?>

Leave a Comment