View Full Version : Delay between statements.
marocnl
Sun 3rd Aug '03, 8:53am
Does anybody know how to do the following:
<?php
echo "Bla1";
--wait 1 sec.--
echo "$Bla2";
?>
What do i use to have the delay between the echo-statements. The first statement has to show up on the page and then the second one should show up after 1 sec.
Floris
Sun 3rd Aug '03, 8:56am
Maybe with exec(sleep 1); ?
marocnl
Sun 3rd Aug '03, 9:15am
Maybe with exec(sleep 1); ?
I don't know.
Maybe it's not possible in PHP. Isn't php first parsing the whole script and then at the end produces the page to be sent to the webbrowser? If this is so, then it's not possible to let it echo 1 statement, wait 1 sec and then put out the second one.
Icheb
Sun 3rd Aug '03, 2:53pm
Just let the script sleep (http://www.php.net/manual/en/function.sleep.php) ;) .
"Maybe it's not possible in PHP. Isn't php first parsing the whole script and then at the end produces the page to be sent to the webbrowser? If this is so, then it's not possible to let it echo 1 statement, wait 1 sec and then put out the second one."
PHP sends the data when it's created, not when the page is finished.
Brad.loo
Thu 7th Aug '03, 5:10am
Just let the script sleep (http://www.php.net/manual/en/function.sleep.php) ;) .
"Maybe it's not possible in PHP. Isn't php first parsing the whole script and then at the end produces the page to be sent to the webbrowser? If this is so, then it's not possible to let it echo 1 statement, wait 1 sec and then put out the second one."
PHP sends the data when it's created, not when the page is finished.
From the comments on the function.sleep page at php.net
hartmut at six dot de
25-Aug-2000 07:38
it is a bad idea to use sleep() for delayed output effects as
1) you have to flush() output before you sleep
2) depending on your setup flush() will not work all the way to the browser as the web server might apply buffering of its own or the browser might not render output it thinks not to be complete
netscape for example will only display complete lines and will not show table parts until the </table> tag arrived
so use sleep if you have to wait for events and don't want to burn to much cycles, but don't use it for silly delayed output effects!
Xelopheris
Fri 8th Aug '03, 2:48am
Why exactly would you want the statement to be delayed? Most often, browsers take a rusty chainsaw to pages with incomplete HTML. However, if you do, remember to flush() before you sleep().
vBulletin® v3.8.0 Beta 4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.