php server push



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

.



Relevant Pages

  • Re: HELP: send binary replies back and forth ???
    ... a client, not a server. ... simple php function to set the timeout), ... Issues in writing php server are: ... >> and communication then goes back and forth between the server and client ...
    (comp.lang.php)
  • Re: How do we get there from here?
    ... >> executing on the server as a pre-processor. ... If there are client side versions of PHP, ... > name implies a static text file, is it different from a PHP script? ...
    (comp.databases.pick)
  • Re: Which Is The Better Approach To Working With Javascript?
    ... However this is achieved, PHP has no script interface, ... Javascript is run **ONLY** on the client. ... but I think the original answers based on the level of the OP were probably good ones; run it client side because the server likely doesn't provide it?. ...
    (comp.lang.php)
  • Re: Implementing a simple persistent web game server
    ... If you're going to use PHP on the server, ... implement from the client end. ... game events. ...
    (comp.lang.php)
  • Re: Help needed in transfering VC++ program to WWW
    ... i have a client server program in VC++,i want to provide this client - ... (such as PHP or ASP.NET) ... and in the local browser environment. ...
    (microsoft.public.vc.mfc)