Echoing code with time intervals

 
Post new topic   Reply to topic    PHP User Group Malta Forum Index // Links to PHP Good Tutorials
View previous topic :: View next topic  
Author Message
yancho
Site Admin


Joined: 13 Nov 2007
Posts: 51
Location: Iklin

PostPosted: Fri Dec 14, 2007 8:36 pm    Post subject: Echoing code with time intervals Reply with quote

 Scenario
Imagine you need a script that gets some data, then
 wait some seconds, and gets another data from a DB
 / Array (I used a for loop), this is how I managed
 to make it, with the help of killfrog Smile

php:


<?

ob_start
();

for (
$i=1$i $i++) {
  echo 
date("H:i:s");
  echo 
"I am displaying after 5 seconds <br>";
  
ob_flush();
  
flush();
  
sleep (5);
}

?>



will output :

Quote:

20:32:32 I am displaying after 5 seconds 
20:32:37 I am displaying after 5 seconds 
20:32:42 I am displaying after 5 seconds 
20:32:47 I am displaying after 5 seconds


Hope it helps some of you Wink

BTW : I was also told that ob_flush() can be
 screwed if you have mod_deflate module loaded in
 Apache.

To check if it is point your browser here : 
http://www.gidnetwork.com/tools/gzip-test.php and give the
 url of a page of yours on your server.

If Web Compression is No you have no problems, if it
 is Yes, it could mean that it will create some
 problems for you. Mine is off, so I couldn't test Sad


Goodluck Wink


_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Post new topic   Reply to topic    PHP User Group Malta Forum Index // Links to PHP Good Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

alexisRed v1.2 // Theme Created By: Andrew Charron and Web Hosting Bluebook // Icons in Part By: Travis Carden
Boards optimised using the phpBB-SEO mod found at phpbb-seo.com
Boards hosted courtesy of solutions-lab.net
Link Backs : PHPClasses.org - MT Page :: PHPUsergroups.org - MT Page



Powered by phpBB © 2001, 2002 phpBB Group