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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
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?
If you only need to support HTML5 browsers, the client side will be much easier. Check stackoverflow.com/questions/1253683/websocket-for-html5 for a list of server side implementations for different platforms
Wicked, thanks, that's what I needed, a PHP solution without having to install much new server-side stuff. I'll take a look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.