Mechanism for Server Push with Apache and Perl
I'm looking to add some sort开发者_JAVA技巧 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?
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
精彩评论