If you have access to your php.ini file, then correct its permission and edit it accordingly.
You can also create an empty php.ini in your public_html (root directory) and just add a line for maximum execution time.
But another way to handle maximum execution time is that, you can add to the default PHP timer using set_time_limit()
, but not definitely in the very first line. It adds to the timer, it does not set a default value as does php.ini, also as PHP Documentation says, you cannot use in if php is run in safe_mode.
It is better, if after all you do not have access to php configuration, to handle your script using set_time_limit()
. You can make a time utility manager for such purpose. Use set_time_limit()
in the heart of your script when you think time is running out. For instance:
while(true)
{
if(get_time_of_my_script() == 25) // assuming php.ini's limit is 30 seconds
{
set_time_limit(20); // add 20 more seconds
}
}
function get_time_of_my_script()
{
// write something that calculates your execution time from the
// very first line till the invocation
// of the function
}
Though you should bear in mind that:
All timing settings of php is limited to the PHP internally. If you execute a system()
call then it is not under PHP's control until it returns something. Therefore, if you are dealing with DB, make sure about timing of DB engine.
Other environmental settings such as Apache/IIS timing settings would normally limit PHP after a certain length of time (though their default is 300 seconds which is adequate probably for you).