与 Apache/PHP/Javascript 的长期连接(异步服务器推送)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/399366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:05:43  来源:igfitidea点击:

Long-lived connections (asynchronous server push) with Apache/PHP/Javascript?

phpjavascriptjqueryajaxapache

提问by cletus

I come from more of a Java background. In the last year or two, it's become somewhat popular to do server pushover HTTP using long-lived HTTP connections in Comet. It's an extremely useful technique.

我来自更多的 Java 背景。在过去的一两年里,在 Comet 中使用长期存在的 HTTP 连接通过 HTTP 进行服务器推送变得有些流行。这是一种非常有用的技术。

So I'm curious what the equivalent is with Apache + PHP + Javascript? One option I see is just using straight AJAX calls (eg with jQuery) but I don't really know how Apache handles them or how I can implement such a thing on the serverside with PHP. Any ideas? Any good resources on this kind of thing?

所以我很好奇 Apache + PHP + Javascript 的等价物是什么?我看到的一个选择是直接使用 AJAX 调用(例如使用 jQuery),但我真的不知道 Apache 如何处理它们,或者我如何使用 PHP 在服务器端实现这样的事情。有任何想法吗?这种东西有什么好的资源吗?

回答by Brian Fisher

You can use Comet programming techniques in PHP. I think a good place to start is this post, describing how to implement Comet in PHP.

您可以在 PHP 中使用 Comet 编程技术。我认为这篇文章是一个很好的起点,它描述了如何在 PHP 中实现 Comet。