Keeping script alive when set_time_limit() not there?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Keeping script alive when set_time_limit() not there?

Post by kkonline »

Hi,
Is there anyway i can keep a script running till it completes if set_time_limit(0); is not allowed?
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: Keeping script alive when set_time_limit() not there?

Post by mattcooper »

Do you have access to the php.ini config file? If so, look for this block and alter accordingly:

Code: Select all

 
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
 
max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M      ; Maximum amount of memory a script may consume (128MB)
 
If not, use the ini_set() function in your applicationconfig/bootstrap file:

Code: Select all

 
<?php
    $intTimeInSeconds = 300; // or however long you want to keep your script running
    ini_set('max_execution_time', $intTimeInSeconds);
?>
 
There are other methods, but one of the above should work for you - and do make sure PHP isn't running in safe mode ;)
Post Reply