Simon Willison’s Weblog

Subscribe

How are real time web applications achievable with PHP?

9th January 2011

My answer to How are real time web applications achievable with PHP? on Quora

You don’t need to build your comet server using the same technology as the rest of your site.

I build apps in Django, which isn’t really suitable for comet due to its core expectation that an HTTP request/response cycle returns immediately rather than blocking. If I was building a comet application, I’d have the main site served by Django and then run a Node.js or Twisted or Tornado server on a separate subdomain (comet.example.com) and have my comet calls served by that.

Quora does something similar to this—if you run Firebug or similar you can see that Quora’s comet servers run on subdomains with names like tch972015.tch.www.quora.com. This also makes it easy to scale your comet stuff since you can just fire up more servers on more subdomains—you don’t even need to load balance them (though you probably should). I believe they use the same Python stack for Comet and the main site, but there’s no reason you have to.