"Push" information via PHP

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
danc81
Forum Newbie
Posts: 16
Joined: Mon May 11, 2009 2:00 pm

"Push" information via PHP

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: "Push" information via PHP

Post 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.
danc81
Forum Newbie
Posts: 16
Joined: Mon May 11, 2009 2:00 pm

Re: "Push" information via PHP

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: "Push" information via PHP

Post 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).
Post Reply