tags:

views:

124

answers:

4

For example, my goal is to test the code given here:

http://stackoverflow.com/questions/863268/php-script-that-reports-progress-to-client

<?php

waitalittle();
echo 'Task one finished';
flush();

waitalittle();
echo 'Task two finished';
flush();

?>

My objective is to create the waitalittle() function, which should take 5 seconds to execute.

My final goal is to be able to view the progress of various parts of my PHP script in the browser without having to refresh.

The issue I'm having now is that if I use any-old function instead of "waitalittle", all the echoed statements appear at the same time. I want to test the above mentioned link/answer to see if statements are echoed on the browser as they are processed.

+2  A: 

See sleep:

int sleep ( int $seconds )
Delays the program execution for the given number of seconds.

So your waitalittle function could look like this:

function waitalittle() {
  sleep(5);
}
Dominic Rodger
+5  A: 

sleep() will wait for you. It's so nice. :)

Ólafur Waage
+1  A: 
<?php
sleep(5);
echo 'Task one finished';
flush();

sleep(5);
echo 'Task two finished';
flush();

?>
Lucas Hrabovsky
+1  A: 

you can use this instead of waitalittle()

sleep(5);

or else in your way it is

function waitalittle() {
sleep(5);
}
atif089