PHP server-push

Frank Johnson<ratty at they.org> -- Please email me if you find this script useful.

huh?

If you have a webcam or something that can take a pic over and over and put it in the same spot (like most webcam software) this PHP script will allow you to display your image on a webpage.

For more information see Netscape's page on server-push.

Requirements

Works with Apache-1.3.14/PHP4.0.3pl1 server and Various Netscape clients. Probably many other server combos. Tested on Netscape 4.7x and 6.0/Mozilla.
Does NOT WORK WITH IE. Internet Exploiter does not support x-mixed-replace server-push as far as I know. If a browser has "MSIE" in its User-Agent string the script will display one image and exit.
Update 20020108: Poked around freshmeat for a bit and found Andy Wilcock's Cambozola java applet which seems to work well with my php script to make the stream viewable under IE. Beware that the current version doesn't work under "Name-based" virtual hosts but I'll have a patch for it soon.

Source

Download

<?

header
('Content-type: text/plain');
print <<<EOF
<?
  
\$file = "./latest.jpg";
  
\$sep = "gIrLsKiCkAsSiTsAySsOoNaTsHiRt";

  if (ereg(".*MSIE.*",
\$HTTP_SERVER_VARS["HTTP_USER_AGENT"]))
  
{
# If IE, spit out one pic and exit
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    header("Content-type: image/jpeg");
    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");
    print "--
\$sep\\n";
    do 
{
      print "Content-Type: image/jpeg
\\n\\n";
      readfile(
\$file);
      print "
\\n--\$sep\\n";
      flush();
      
\$mt = filemtime(\$file);
      do 
{
        sleep (1);
# we won't output the same image twice.
        clearstatcache();
      
} while (\$mt == filemtime(\$file));
    
} while (1);
  
}
?>
EOF;

?>

Make sure there are no blank lines outside the <? ?> in your script. That will cause screwey headers to be sent too soon.
Reference the script in your HTML page as if it was an image:

<IMG SRC="server-push.php" HEIGHT=240 WIDTH=320>

Use this bit of PHP on the page that references the image to compensate for IE's lack of "innovation":

<HEAD>
<?
    
if (ereg("MSIE",$HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
        echo
"<META HTTP-EQUIV=\"Refresh\" CONTENT=\"4;\">\n";
    }
?>
</HEAD>

Other software by me