1

Is there a way in HTML5 (websocket perhaps?) to set up some kind of push mechanism for ajax requests? For instance, I would like my logged in user to be notified he has a new message without sending a periodic ajax request to the server checking if there actually is a new message.

Right now, I do a check every couple seconds and change the UI accordingly if I get a number back, but for 10000 users this tends to get quite demanding on the server with frequent updates.

If HTML5 does not have a native ability to handle this, is Comet (http://www.zeitoun.net/articles/comet_and_php/start) a better approach than periodic ajax calls?

Swader
  • 11,387
  • 14
  • 50
  • 84

1 Answers1

1

Comet is made for that exact purpose, but Websockets in HTML5 will offer much better performance. See https://stackoverflow.com/questions/4262543/what-are-good-resources-for-learning-html-5-websockets

However, Websockets aren't supported in most browsers yet, so you'll need a library to serve as a layer of abstraction between your application and the specific implementation supported by the current browser (using WebSockets if they are available, but falling back to long-polling, Flash sockets, etc. as necessary). Fortunately there are plenty of libraries like that.

To find an appropriate implementation for your app, you should take a look at CometDaily's Comet Maturity Guide. Not mentioned there, however, is the APE project (Ajax Push Engine), which is gaining a lot of traction with web application developers right now.

Community
  • 1
  • 1
Jens Roland
  • 27,450
  • 14
  • 82
  • 104
  • That's ok, I only need it for the most recent version of Chrome. Can you link to some resources about this if you have any at hand? – Swader Aug 17 '11 at 10:56
  • I see. I would still like to do it with Websockets - I am 100% sure I will never need it on any browser other than Chrome or the most recent Firefox. Will I also need to install a different/upgraded Apache server in order to support websockets, or is this supported natively? – Swader Aug 17 '11 at 11:15
  • 1
    If you only need to support HTML5 browsers, the client side will be much easier. Check http://stackoverflow.com/questions/1253683/websocket-for-html5 for a list of server side implementations for different platforms – Jens Roland Aug 17 '11 at 11:34
  • Wicked, thanks, that's what I needed, a PHP solution without having to install much new server-side stuff. I'll take a look. – Swader Aug 17 '11 at 11:57