Forum Moderators: coopster

Message Too Old, No Replies

Sleep() function again

sleep(), pausing script execution

         

villek

10:38 am on Mar 17, 2004 (gmt 0)



There was a thread here on the subject, but it has been closed so...


$between_delay = 10; $send_delay = 1; for ( $sent=0; $row = mysql_fetch_array($result); $sent++ ) { if ( ($sent % $between_delay) == 0 ) sleep( $send_delay ); $emailall = $row[0]; $message = stripslashes($message); mail("$emailall", "$subject", "$message", "From: $email"); }

That's a nice piece of code, but it doesn't do the trick if I want the user to see what's going on.

What I would like to do is this:

1)execute the script 10 times then pause was 10 seconds

2)notify the user that the script is pausing

3)continue executing after the pause

4)tell the user, how many emails habe been sent before the pause

Is there any way to do this? I've tried out different sleep() tests, but all of the seem to sleep() for the give amout of time and when they're done sleeping, they'll output the whole thing at one time, like this one for example:

while ($x<10) {

$x++;

if($x==5) {

sleep(5);

$msg = "Script executed " . $x . " times. Wait 5 seconds an continue"

print "" . $msg . "<br />";

print "" . date('h:i:s') . "<br />";

}

else if($x==10) {

sleep(5);

$msg = "Script executed " . $x . " times. Wait 5 seconds an continue"

print "" . $msg . "<br />";

print "" . date('h:i:s') . "<br />";

}

}

That script waits for 10 seconds then prints:
<i>
Script executed 5 times. Wait 5 seconds an continue"

17.2.2004 11.23.25

Script executed 10 times. Wait 5 seconds an continue"

17.2.2004 11.23.30</i>

And that's not what I'm looking for. Any ideas?

justageek

11:45 am on Mar 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to use use flush() to output the buffer after each print. Remember also that the script will stop by default after 30 seconds unless you use set_time_limit() and even then it will stop when the web server decides to stop it.

JAG

gethan

12:27 pm on Mar 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Didn't look at details of your application. But another generic approach is to:

divide your application into a series of stages.

start stage 1

use javascript to pause the browser

next stage

repeat above 2 steps until done.

HTH