Server Push Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Server Push Issue

Post by thomas777neo »

Please can someone urgently help me, I managed to get an image to be pushed from the server using this code:


server.php

Code: Select all

$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);
  }
client.php

Code: Select all

<img src="server.php">
If you open the client.php script, it shows the latest.jpg. If you replace the image with another latest.jpg, it automatically pushes the new image from the server to the client, and then shows the new image.

What I would like to do however is have an sql statement run, if it returns rows, then push the information back to the client side.

It would be much appreciated if someone could simply show me how to modify his script to get that result. I tried changing the Content-Type to text/html and tried replicating the logic of the script using an sql statement that ran in a while(true) loop. But I couldn't get the right output to the client.php.

I think it has something to do with output buffering. I don't know???
Post Reply