开发者

PHP, Apache, Mysql, HTML5 - getting changes from server without requesting them (push)

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 th开发者_如何学JAVAere 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜