PHP、Apache、Mysql、HTML5 - 从服务器获取更改而不请求它们(推送)

发布于 2024-11-30 01:08:03 字数 297 浏览 0 评论 0原文

HTML5(也许是websocket?)有没有办法为ajax请求设置某种推送机制?例如,我希望我的登录用户收到通知,他有一条新消息,而无需定期向服务器发送 ajax 请求来检查是否确实有新消息。

现在,我每隔几秒钟进行一次检查,如果收到号码,就会相应地更改 UI,但对于 10000 个用户来说,这往往会对频繁更新的服务器提出相当高的要求。

如果 HTML5 没有原生能力来处理这个问题,Comet (http://www.zeitoun.net/articles/comet_and_php/start) 是否是比定期 ajax 调用更好的方法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜光 2024-12-07 01:08:03

Comet 就是为了这个目的而设计的,但 HTML5 中的 Websockets 将提供更好的性能。请参阅https://stackoverflow.com/questions/4262543/what -are-good-resources-for-learning-html-5-websockets

但是,Websockets 大多数浏览器还不支持,因此您需要一个库来充当应用程序和当前浏览器支持的特定实现之间的抽象层(如果它们是可用的,但根据需要回落到长轮询、闪存套接字等)。幸运的是,有很多这样的图书馆。

要为您的应用找到合适的实现,您应该查看 CometDaily 的 Comet 成熟度指南。然而,那里没有提到的是 APE 项目(Ajax Push Engine),它正在获得很多成果目前对 Web 应用程序开发人员的吸引力。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文