Hello
I need to use a PHP server-push technology to bring data (text) onto a dynamic webpage in order to refresh the page as soon as the data changes. Since I've not found any examples of this subject, I did a little test by changing the PHP algorithm to refresh pictures from a webcam. I'm quite new to PHP, so there might be some mistakes in the script. The problem is this : when setting the "sleep"-value smaller than 1, the text displays way too fast (1-100 in a couple of seconds). But when I increase the value to 1 or higher, I get something like "test number 30". Can someone tell me how to make sure that the text refreshes say, every second?
This is my test.php :
<?php
$k = 0;
$end = "Finish"; // random string
header ("Content-type: multipart/x-mixed-replace;boundary=$end"); //define header for server push
print ("--$end\n"); //start data
while ($k<100)
{
print ("Content-type: text/plain\n\n"); //define data type
echo ("Test number $k"); //data output
$k++;
if ($k==100)
print ("\n--$end--\n");//end of data
else
print ("\n--$end\n"); //start data
flush (); //clear buffer
sleep (1); //pause between reloads
}
?>
Thank you.