php server push

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, (i hope this is the right place to ask questions like below)

I am trying to use content type 'multipart/x-mixed-replace' to 
achive server pushing and I have the following piece of code, which works perfectly.

/* file.html */
function handleContent(event)
{
  var result = event.target.responseXML;
}

var xrequest = new XMLHttpRequest();
xrequest.multipart = true;
xrequest.open("GET","file.php",true);
xrequest.onload = handleContent;
xrequest.send(null);

/* file.php */

<?php
  header('Content-type: multipart/x-mixed-replace;boundary="rn9012"');
  print "--rn9012\n";


  /* 
	With these prints i can generate an event on the browser side. 
	For instance if I would like to wait for sg to happen on the server side i can
	make an infinite loop and wait. when sg happens i just print the event.

  */
  while (true) {
    print "Content-type: application/xml\n\n";
    print "<?xml version='1.0'?>\n";
    print "<content>event1</content>\n";
    print "--rn9012\n";
    flush();ob_flush();
  }


  sleep(5);

  /* I close the connection with this event. Closing tag: with 2 extra -- */
  print "Content-type: application/xml\n\n";
  print "<?xml version='1.0'?>\n";
  print "<content>last event</content>\n";
  print "--rn9012--\n";

?>

BUT I have to keep an infinite loop on the server side for each clients
just to be able to send and event (let's say in every 3rd hour)

Is there a way with which i can keep the connection without the infinite loop,
and send the event message to the client from a different php file?

/* file2.php */
<?php
	/* this is what i wish */
	send_event_toclient(clientid, eventmessage);
	//clientid: id of the client that i had saved before
	//i think this id should be sg socket where i can write the output to. 

?>

I hope I cound explain my problem clearly
thank you in advance

Christian Guttmann


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux