Ajax push system

You can achieve push within PHP but it won’t be the most efficient solution because to achieve push you need to maintain long running connections between your client and your server (HTTP or WebSocket connections).

See:

General best practice when building a realtime infrastructure has been to decouple the push solution from your web application (Note: node.js and socket.io has changed this a bit, but personally I still think it should be decoupled). But, assuming that the latter is still the best solution you would need to write/host/install this push solution. Decoupling also means that the technology doesn’t have to be PHP but you can access/use it from PHP. Maybe a bit of overkill? And especially if you don’t have too many users on your site?

For simplicity I would recommend looking at using a 3rd party hosted service. I work for one such company called Pusher. Using a service such as ours lets you remove the need to install and maintain the realtime part of your application. It also makes it really easy to add the push functionality you are looking for. All you need to do is add a few lines of PHP code to your existing app to trigger the push notifications and add a few lines of JavaScript to your front-end.

Resources:

If you’d like to investigate the alternatives or some of the technologies I’ve mentioned above I’m maintaining a list of realtime technologies which you might also be interested in.

Leave a Comment