Page 1 of 1

"Push" information via PHP

Posted: Sat Nov 07, 2009 6:42 am
by danc81
Hi,

I'm wondering if it's possible to design a system that can "push" information to a connected client using PHP/Apache. My idea is that a client sets up a connection and waits for the server to return a response indicating that there is new information waiting on the server. If I built the server, I would probably have some sort of internal connection list with an identifier associated with each connection and when new information became available I would know exactly which connection to send the response to. My question is, is something like this possible with PHP, how can I keep an internal "list" of connected clients and trigger a response to one on demand?

Thanks

Re: "Push" information via PHP

Posted: Sat Nov 07, 2009 2:12 pm
by John Cartwright
If you truly need the server to push messages to the clients, then take a look at one of the many "Comet" implementation.

Re: "Push" information via PHP

Posted: Sat Nov 07, 2009 2:22 pm
by danc81
Thanks for the replies, I understand that HTTP is a request/response protocol but given the right settings there's no reason why I couldn't have a keep-alive connection which initiates a request and wait indefinitely for a response, in C++ terms is would be something like a WaitForSingleObject() call blocking until an event happens and spits out a response. Obviously not that simple in PHP, especially when it comes to load balancing across multiple servers but just trying to figure out if it's worth persuing.

Do you have a link to Comet? I've never heard of it, I'm looking into XMPP PUB-SUB at the moment which looks promising, not PHP but a possibility.

Re: "Push" information via PHP

Posted: Sat Nov 07, 2009 3:17 pm
by John Cartwright
It isn't really practical with PHP to keep the connection alive, and it generally won't scale well on high volumes. A good resource if you want to look into "comet" furthur is http://cometdaily.com/ -> http://cometdaily.com/maturity.html, although it will take a bit of searching to find an implementation that suits your needs (i.e., server, languages, pricing).