使用 Apache 和 Perl 进行服务器推送的机制
我希望向在 Apache 之上使用 Perl 构建的页面添加某种类似 HTTP 推送的功能,通过长轮询或其他标准方式实现。
有没有办法在不设置单独的服务器(例如 Meteor 或 Stardust)的情况下执行此操作?是否有一个模块可以帮助服务器代码?除了长轮询还有其他方法吗?
I'm looking to add some sort of HTTP push-like functionality, implemented via long polling or another standard means, to a page built with Perl on top of Apache.
Is there a way to do this without setting up a separate server such as Meteor or Stardust? Is there a module that would help with the server code? Is there a way other than long polling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要快速而肮脏的修复以避免对当前应用程序或设计进行重大更改,并且不需要即时更新,那么一种简单的方法是使用从浏览器到服务器的常规 AJAX 轮询。
换句话说,您的浏览器中的 JavaScript 每隔几秒钟检查一次服务器,以查看服务器上是否有此浏览器会话的任何消息和/或数据。这很可能不会很好地扩展,特别是在轮询超时很短的情况下,并且会耗尽服务器资源,但这可能是一个有用的权宜之计。
只是重申一下,这只是一个快速修复解决方法 - 普遍共识是您需要使用 COMET(可能在您的情况下在单独的服务器上)作为正确的解决方案(直到 websockets 到达...) - 请参阅这些链接中的一些很好的分析:
http://cometdaily.com/2007/11 /06/comet-is-always-better-than-polling/
http://stackoverflow.com/questions/2975290/comet-vs-ajax-polling
If your need a quick and dirty fix to avoid major changes to your current application or design, and you do not need instant updates, then one simple approach is to use regular AJAX polling from the browser to the server.
In other words you would have javascript in your browser check the server every couple of seconds to see if there is any message and/or data on the server for this browser session. This will most likely not scale very well, especially with short poll timeouts, and will eat up server resources, but it may be a useful stopgap solution.
Just to reiterate, this is just a quick fix workaround - general consensus is you need to use COMET (probably on a separate server in your case) as a proper solution (until websockets arrive...) - see some good analysis in these links:
http://cometdaily.com/2007/11/06/comet-is-always-better-than-polling/
http://stackoverflow.com/questions/2975290/comet-vs-ajax-polling