I have a snippet of code I got from a fellow named Frank Reynold's site.
I've amended it such that if I have a file, which I call getdata.txt, which
is a text file which an application writes to a server sporadically and
frequently, and I wish that text to be visible in a browser window, this
accomplishes that. Anytime getdata.txt is changed on the site, it is
reflected in the browser.
HOWEVER, since a php script times out (typically in 30 seconds, the
default), this wonderful little thing dies every 30 seconds. Can anyone tell
me a way (other than changing the time out value in php.ini !) how to make
this run indefinitely. Any kind of hack someone can point me in the
direction of here? Thanks, Ike
<?php
$file = "./getdata.txt";
$maxexectutiont ime=10;//set in php.ini
$sep = "ofaLlTherCrzyT hInggsIhaveayea rd";
$a=0;
$b=0;
if (ereg(".*MSIE.* ",$HTTP_SERVER_ VARS["HTTP_USER_AGEN T"]))
{
# If IE, spit out one time and exit
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-type: text/plain");
header("Content-size: " . filesize($file) );
readfile($file) ;
}
else
{
# if not IE, give the browser a try
header("Content-Type: multipart/x-mixed-replace; boundary=$sep") ;
do {
print "Content-Type: text/plain\n\n";
readfile($file) ;
print "\n--$sep\n";
flush();
$mt = filemtime($file );
do {
$a++;
if($a>=$maxexec tutiontime-1){
$b=-1;
}else{
sleep (1);
# we won't output the same data twice.
clearstatcache( );
}
} while ($mt == filemtime($file ) && $b==0);
} while ($b==0);
}
?>
I've amended it such that if I have a file, which I call getdata.txt, which
is a text file which an application writes to a server sporadically and
frequently, and I wish that text to be visible in a browser window, this
accomplishes that. Anytime getdata.txt is changed on the site, it is
reflected in the browser.
HOWEVER, since a php script times out (typically in 30 seconds, the
default), this wonderful little thing dies every 30 seconds. Can anyone tell
me a way (other than changing the time out value in php.ini !) how to make
this run indefinitely. Any kind of hack someone can point me in the
direction of here? Thanks, Ike
<?php
$file = "./getdata.txt";
$maxexectutiont ime=10;//set in php.ini
$sep = "ofaLlTherCrzyT hInggsIhaveayea rd";
$a=0;
$b=0;
if (ereg(".*MSIE.* ",$HTTP_SERVER_ VARS["HTTP_USER_AGEN T"]))
{
# If IE, spit out one time and exit
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-type: text/plain");
header("Content-size: " . filesize($file) );
readfile($file) ;
}
else
{
# if not IE, give the browser a try
header("Content-Type: multipart/x-mixed-replace; boundary=$sep") ;
do {
print "Content-Type: text/plain\n\n";
readfile($file) ;
print "\n--$sep\n";
flush();
$mt = filemtime($file );
do {
$a++;
if($a>=$maxexec tutiontime-1){
$b=-1;
}else{
sleep (1);
# we won't output the same data twice.
clearstatcache( );
}
} while ($mt == filemtime($file ) && $b==0);
} while ($b==0);
}
?>
Comment