views:

272

answers:

2

I am trying to understand how push services work. I believe push notifications are where the server 'pushes' a new item to the client, but I don't know how that works in practice.

For example, how does a phone "know" that it has a new email to pick up if it doesn't manually check the server for a new message?

Also, how can this be implemented for a chat program or notification system for a small website? Are there php classes out there, etc..?

+2  A: 

I'm assuming you are talking about an HTTP client? It is generally done with Server push or Comet technology. Instead of simply closing the HTTP connection after a page loaded clients keep the connection open to receive server push messages.

Have a look at this SO entry for some details on how to do it with JQuery.

There are some examples for PHP on the web although you might want to look at a cometd server if you expect more than just a handful of connections otherwise you might run out of Apache server connections.

leonm
+4  A: 

For example, how does a phone "know" that it has a new email to pick up if it doesn't manually check the server for a new message?

PUSH implementations vary, depending on the protocol, but the principles remain the same. A connection is kept open between the client and server and the client is notified by the server of new events. This utilises less bandwidth and typically leads to faster interaction than the client periodically asking the server whether there are any new events waiting.

As a demonstration, this is how PUSH IMAP (known as IDLE) mail works:

  1. The client logs into the email server as normal.
  2. During the login process the server advertises that it is capable of IDLE.
  3. The client performs a check and download of new messages as normal.
  4. Instead of periodically polling for new messages the client issues an IDLE command.
  5. The session between the server and client remains quiet.
  6. When new mail arrives and the server notifies that the messages EXISTS.
  7. The client can then exit IDLE mode with DONE and download those messages.
  8. Repeat from step 4.
Dan Carley
thanks, does using push (like in the example you describe above) put more of a load on the server than just polling every 1 second?
chris
Au contraire. It should result in a reduction of server load, with a slightly higher use of concurrent connections and threads. When compared to a constant login and poll cycle.
Dan Carley