Web Hosting Talk







View Full Version : Help with sleep()


datruesurfer
08-09-2005, 11:10 PM
I have been trying to use the sleep function to test somthing out with PHP and need some help. I want it to work like cPanel does when its creating accounts and text automatically appears on the screen while the script is running without refreshing the page (if that makes any sense at all ). For example:

CODE
<?php
$now = date('h:i:s');
echo "The time is $now . Sleeping for 10 seconds...";
sleep(10);
$later = date('h:i:s');
echo "After 10 seconds the time is $later";
?>


What I want to do is have the first echo call executed and display on the users browser, wait 10 seconds and display the second echo statement on the users browser rather than waiting 10 seconds for both to display on the browser.

Anyone know what I'm taliking about?

kailash
08-10-2005, 12:47 AM
Sleep wont serve your purpose !
You are ob_start() and related functions.
http://php.net/ob_start

Here's a sample.

<?php

// Output buffering start
if (ob_get_level() == 0) ob_start();

// Your process here that you need to spit out contents
// as an output is produced.. ...............
ob_flush(); // These two come in your for loop, or whatever usuallly
flush();



?>

datruesurfer
08-10-2005, 02:12 AM
That worked, thanks :D

kailash
08-10-2005, 02:58 AM
You are ob_start() and related functions.

Sorry, that was a typo. It should be

You are looking for ob_start() and related functions.


Thanks anyway !