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..?
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:
IDLE
.IDLE
command.EXISTS
.IDLE
mode with DONE
and download those messages.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With