Thursday, September 28th, 2006

COMET with PHP

Category: PHP

<p>Manuel Lemos has written a post about
the details and challenges of an AJAX COMET implementation in PHP
.

The article describes an approach used to implement highly responsive AJAX applications using the COMET approach, and how it can be implemented in PHP.

It also discusses how HTTP compression and chunking affect AJAX response delays, as well aspects that may influence the choice between Apache 1.3.x with mod_gzip versus Apache 2.x with mod_deflate for AJAX COMET applications.

Community Question: Are any of the PHPers out there doing COMET? If so, do you have anything to add about the experience?

Related Content:

  • PHP
    PHP is a script language and interpreter that is freely available and used primarily on Linux Web servers. PHP, originally derived from Personal Home...
  • Developing composite applications with PHP - Advanced AJAX
    A better way to store client-side ID, main work on the server side (requiring close collaboration between the server-side PHP script and the...
  • Turnaround expert linked with Comet
    An entrepreneur that has a track record in turning around struggling businesses has been linked as a possible buyer for the struggling retailer...
  • Comet sale edging closer
    The sale of the Comet electrical chain could be moving towards a conclusion with a private equity firm the most likely buyer to take the retail chain...
  • Snow hits Comet results
    Bad weather took its toll on electrical retailer Comet's performance over the winter period as its parent Kesa Electricals blamed the snow for...

Posted by Dion Almaer at 9:27 am
12 Comments

+++--
3.7 rating from 77 votes

12 Comments »

Comments feed TrackBack URI

My understanding is that PHP is a terrible language for Comet, because Comet requires you to keep a persistent connection open to each browser client. Using mod_php this means tying up an Apache child full-time for each client which doesn’t scale at all. The people I know doing Comet stuff are mostly using Twisted Python which is designed to handle hundreds or thousands of simultaneous connections.

Comment by Simon Willison — September 28, 2006

Another language to look at is Ruby. Using Ruby’s Event Machine you can scale to loads of connections easily as it has a non blocking io. This is the method the new version of juggernaut (Comet for ruby on rails) is using.

Comment by Alex MacCaw — September 28, 2006

Simon is partially right in that PHP doesn’t easily let you do Comet. mod_php doesn’t let you keep connections open for extremely long periods of time (because that violates PHP’s “shared-nothing” architecture that allows it to scale well). If you’re going to do Comet in PHP you have to cheat and either do polling with a very short interval or create an XMLHttpRequest connection that is long-lived. Check out this info at AjaxPatterns.org for more information on this idea by a guy way better at explaining it than me.

Comment by Chris Hartjes — September 28, 2006

This approach has nothing to do with COMET – i was very disappointed reading this one on dzone yesterday. Firing a request on multiple IFRAMES – well… COMET is something else. Nice idea though but mischosen topic!

Comment by .mario — September 28, 2006

Mario, there seems to be a misundersanding. This implementation does not fire a request on multiple iframes. It just a single request to a single iframe that may a stream of multiple chunks of Javascript code to execute customizable actions on the browser side upon events that happen on the server side. The chunks of Javascript code are sent independently of each other to the browser using a single connection. The article explains why it is important to assure HTTP 1.1 chunked responses are used, so the Javascript chunks are flushed to the browser right after each event occurs on the server side.

Comment by Manuel Lemos — September 28, 2006

Simon, the problem of scalability is not so much on PHP but rather on the Web server mode that you use to run PHP. If you use Apache with pre-forked processes, it consumes much more memory than using Apache or some other Web server in multithreading mode. PHP core extensions and the execution engine (Zend engine) are thread-safe. What is not thread safe are some extensions and libraries that may be needed to run your scripts. Another alternative to run PHP with a multithreaded Web server, is FastCGI. It may not be as fast as mod_php, but it may handle much more simultaneous connections with the same amount of memory.

Comment by Manuel Lemos — September 28, 2006

scat slave

girl squirt uncut white boy cock mature latina

Trackback by Anonymous — October 13, 2006

sperm shack

amateur blowjobs french orals cumtv

Trackback by Anonymous — October 13, 2006

I’ve written something about it at this blog, but I call it LazyHttp, I think the “Comet Washing Brand” is just overdoing it… ;)

Comment by Thomas Hansen — March 21, 2007

私にまだ私がそれを決して….聞かなかったあなたのDVDがある何ものためにまだ働いてhttp://www.canttakeitanymore.comで実質の仕事をあとで得なさい

Comment by silentgnome — April 17, 2007

interseting blog

Comment by hale — June 21, 2007

Has this changed yet? What are my options in implementing Comet with php?

Comment by mg7282 — March 2, 2011

Leave a comment

You must be logged in to post a comment.