Tips and tricks for LAMP (Linux Apache MySQL PHP) developers.

When I cant find a suitable solution to a problem and have to work it out for myself I'll post the result here so hopefully others will find it useful. (All code is offered in good faith. It may not be the best solution, just a solution).

Tuesday 10 June 2008

Comet server-push framework

I've just been asked to look into a way to 'stream' information from the server to any listening clients. Basically it's a server-push rather than client-pull system where changes made on one client are (almost) immediately reflected on all other clients. This is similar to AJAX in that there is no page refresh but it is more autonomous.

I've been reading up on Comet, which is basically just a term for a kind of AJAX solution to this problem, but it doesn't specify any implementation suggestions.

Bayeux takes this a step further by actually outlining a protocol for message transfer between client and server.

Most implementations on the server-side are in Java but we need PHP. I've tracked down a PHP implementation called Comep that works quite well on the server-side (although its procedural rather than OO based) and I'm going to look into replacing its vanilla-javascript client-side with this jQuery Comet plugin.

For any other LAMP developers interested in Comet a good place to start is the Comet Daily Blog.

Update, 2008-06-15: Although PERL rather than PHP based it is also worth mentioning Meteor, which is a highly polished comet server implementation.