Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time before re-run

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
0
0
How to make a php code is capable of waiting for a given number of seconds before re-run again?
Thanks in Advance.
 
php is not the right tool for this. a cron job that runs a php script would be better.

but perhaps something like this would kind of work

Code:
$delay = 10; //seconds
$timeout = 30;//timeout in seconds
$function = 'functionName';//name of function
$force = true;
while ($force){
 set_time_limit ($timeout); //reset the timeout counter
 sleep ($delay); // wait a while
 $function(); // run the function
}

make sure that $timeout > $delay
and also bear in mind that this script is going to be very difficult to cancel once it starts. you'll have to kill the php process. or perhaps add a filesystem check into the loop so that you can at least create a kill file if needs be.
 
You are right jpadie,
but I need to send email to my 1500 newsletter subscribers, my code must loop and retrieve the email addresses form the database and send first 100, then the code must stop for 5 seconds and retrieve the next 100 etc ... , to give the SMTP server a considerable chance to flush some memory.
any idea?
 
use a mailing list manager then - there are loads of freee/shareware versions out there. or use phpmailer with its own smtp class.

my method may work above but it would be as easy to increment a counter once per loop and then add a test in there:

Code:
if ($counter == 50){
 set_time_limit(120);
 sleep(30);
 $counter = 0;
} else {
 $counter ++;
}

just insert the code in your sending loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top