Alex Rivera | Logout

Scaling a chat app - short polling vs. long polling (AJAX, PHP)

Asked 2011-03-15T15:02:02.197
34

I run a website where users can chat with each other through the browser (think Facebook chat). What is the best way to handle the live interaction? (Right now I have a poll going every 30 seconds to update online users and new incoming messages, and another poll going on chat pages every second to get new messages.)

Things I've considered:

  • HTML5 Web Sockets: didn't use this because it doesn't work in all browsers (only chrome).
  • Flash Sockets: didn't use this because I wanted to eventually support mobile web.

Right now, I am using short polling because I don't know how scalable AJAX long polling would be. I'm running a VPS server from servint right now (running apache). Should I use long polling or short polling? I don't need absolutely immediate response times (just "good enough" for a chat app). Is short polling this often with a few hundred-thousand users going to kill my server? How do I scale this, please help!

Edit
Report

1 Answer

1

If i were you i'd pick a library that uses html5 web sockets yet falls back on flash sockets if html5 isn't available, the browser that fall through the crack should be minute.

Also you should either abandon php or supplement it with a threaded socket server written either in python or ruby with em-websocket.

answered 2011-03-16T14:11:43.530

Your Answer