admin管理员组

文章数量:1353252

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..?

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..?

Share Improve this question asked Oct 3, 2009 at 8:21 chrischris 21.3k29 gold badges78 silver badges90 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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 mand.
  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.

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 etd server if you expect more than just a handful of connections otherwise you might run out of Apache server connections.

本文标签: phpHow does push emailchat work Can it be implemented easily for small websitesStack Overflow