COMET 和 PHP 的解决方案

发布于 2024-08-16 01:08:56 字数 266 浏览 5 评论 0原文

COMET 和 PHP 结合有真正的解决方案吗?基本上,我已经意识到,只要数据库中有新数据,我就需要定期更新用户主页。据我了解,我需要在服务器和客户端浏览器之间打开持久连接,以便在有新信息时立即更新其主页的内容。无需投入大量资源即可使用,但我没有找到任何关于此问题的明确信息。我读过很多文章表明 PHP 不是实现 COMET 的好语言。我的 Web 应用程序完全用 PHP 编写,我不想学习另一种语言,但如果我被迫学习,您会建议一种好的语言开始吗?您认为我可以编写一个接口来解决这个问题吗?

提前致谢。

Is there a real solution for COMET AND PHP combination? Basically, I've come to a point that I need to update a user home page periodically whenever there is new data in the database. As far as I understand, I need to open a persistent connection between my server and my clients browsers to update the contents of their home page as soon as new info. available without dedicating a lot of resources but I had no luck finding anything clear about this issue. I read many articles suggests that PHP is not a good language to implement COMET. My web application is completely programmed in PHP and I don't want to learn another language but if I'm forced to, Would you suggest a good language to start with? Do you think that I can program an interface just to handle this issue?

Thanks in advance.

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

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

发布评论

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

评论(8

万人眼中万个我 2024-08-23 01:08:56

有时我听到人们说 PHP 不太适合 COMET (就像您自己所说的那样) 是因为网络服务器和 PHP 的工作方式 - 主要是因为每个页面有一个进程,这意味着如果您希望有 200 个用户连接到您的服务器,则需要 200 个进程(这对于另外几百个用户来说很快就会成为问题)。

也许该问题的解决方案是使用 nginx_http_push_module

我还没有尝试过(还没有?),但这可能正是我们所需要的......

The times I've heard people say that PHP was not well suited for COMET (like you said yourself) was because of the way webservers and PHP work -- mostly, because there is one process per page, which means if you want 200 users connected to your server, you'll need 200 processes (which can quickly become a problem for a couple of hundred more users).

Maybe a solution to that problem would be to use nginx_http_push_module ?

I've not tried it (yet ?), but it might be just what we need...

独享拥抱 2024-08-23 01:08:56

我正在做一个学校项目,遇到了完全相同的问题。由于每个 PHP 进程都有如此多的内存开销,因此不可能支持每个机器的多个连接。正是在这一点上,我决定改用 BOSHXMPP。这是相当新的技术“浪潮”,但已经有相当多的库可以帮助您。我建议使用 StropeXMPPHP。然后您的客户端可以连接到 BOSH 服务器(我使用的是 Openfire)扩展到每台服务器数千个活动连接。

I was working on a school project and ran into the exact same problem. Because each PHP process has so much memory overhead, it's impossible to support to many connections per box. It was at this point I decided to switch to using BOSH and XMPP. This is a rather new "wave" of technology but there is already quite a few libraries to help you on your way. I would suggest using Strophe and XMPPHP. Then your clients can connect to a BOSH server (I'm using Openfire) and that can scale to thousands of active connections per server.

心不设防 2024-08-23 01:08:56

您无需学习新语言即可实现此类功能。

例如,您可以使用 Quercus (PHP 的 Java 实现)并实现一个服务器Comet 应用程序使用 JVM 内存管理模型。

You don't have to learn a new language to implement such a feature.

For example, you could use Quercus (Java implementation of PHP) and implement a server Comet application using the JVMs memory management model.

清晰传感 2024-08-23 01:08:56

您需要一些解决方案:

  1. 几乎是 COMET 解决方案(使用 php 和一个用 perl 编写的文件):
    http://translate.google.com/translate?js=y&prev=_t&hl=ru&ie= UTF-8&layout=1&eotf=1&u=http://dklab.ru/lib/dklab_ Multiplexor/&sl=ru&tl=en

  2. php 中的精确 COMET 解决方案(这是我想你想要什么):
    http://translate.google.com/translate?hl=ru&sl=ru&tl=en&u=http://dklab.ru/lib/dklab_realplexor/

There are solutions you need:

  1. almost COMET solution (uses php and one file written with perl):
    http://translate.google.com/translate?js=y&prev=_t&hl=ru&ie=UTF-8&layout=1&eotf=1&u=http://dklab.ru/lib/dklab_multiplexor/&sl=ru&tl=en

  2. exact COMET solution in php (this is what you want, I think):
    http://translate.google.com/translate?hl=ru&sl=ru&tl=en&u=http://dklab.ru/lib/dklab_realplexor/

dawn曙光 2024-08-23 01:08:56

您首先需要了解彗星应用程序是什么样的。 wiki 中解释了构建 Comet 应用程序所涉及的概念 Comet(编程)

您需要了解的是,您可以使用任何编程语言来构建 Comet 应用程序,只要它遵循 wiki 中解释的概念

1.Ajax with long polling

2.Streaming

您可以在 简单的“长轮询”示例代码

现在来解决问题 -

1.您使用ajax长轮询,然后使用浏览器(ajax 请求)将不断轮询服务器以获取数据。这可能会耗尽服务器上的内存或在一段时间后降低浏览器的速度。

一些建议

JQuery periodicalUpdater(AJAX 长轮询/服务器轮询)

处理长轮询

RobertFischer / JQuery-PeriodicalUpdater

您需要检查什么来实现这一点 -

a) 您期望数据在服务器上更新的频率。

b) 服务器端脚本在将数据发送到客户端之前将运行多少时间来检查、获取和处理数据。

2.您可以通过以下方式实现流式传输 -

如何使用 PHP 实现 COMET

< a href="http://www.lightstreamer.com/demo/DojoDemo/doc.html" rel="nofollow noreferrer">Lightstreamer Dojo

Dojo 图表 + Lightstreamer Comet 演示

演示

Ajax 推送Engine 或 APE 项目

您需要检查什么 -

a) 您的托管提供商是否允许您在托管服务器上安装这些

b) 您的 RAM 和带宽利用率(您将需要一个专用服务器,其中包含可为您提供的软件包大量 RAM 和带宽)

这取决于您的要求是什么以及如何。你必须分析和接近。

如果您正在实现的是一个小型应用程序,那么您可以使用 Ajax 长轮询,因为您已经分析并处理了这种方法的缺点。

如果您有大型应用程序,则可以进行蒸汽处理。

You would first need to understand what is a comet application like. The concept involved in building a comet application are explained at wiki at Comet (programming)

What you need to understand is that you can use any programming language to build a comet application as long as it follows the concepts explained at wiki

1.Ajax with long polling

2.Streaming

You can check some sample code at Simple “Long Polling” example code

Now coming to the problems -

1.You use ajax long polling then the browser(ajax request) would keep polling the server for data. This may eat up memory on the server or slow down the browser after some time.

Few Suggestions

JQuery PeriodicalUpdater (AJAX long polling/server polling)

Handling Long Polling

RobertFischer / JQuery-PeriodicalUpdater

What you need to check to implement this -

a) How often do you expect data to be updated on the server.

b) How much time the server side script would run to check, fetch and process data before sending it to the client side.

2.You can implement streaming by using the following -

How to implement COMET with PHP

Lightstreamer Dojo

Dojo Charting + Lightstreamer Comet Demo

Demo

Ajax Push Engine or The APE Project

What you need to check for this -

a) Will your hosting provider allow you to install these on hosting servers

b) Your RAM and Bandwidth utilization (You will need a dedicated server with package that gives you lots of RAM and Bandwidth)

It depends on what and how your requirements are. You will have to analyze and approach.

If what you are implementing is a small application you can go for Ajax Long polling given the fact that you analyzed and handled the negatives of this approach.

If you have a large application you can go for steaming.

素食主义者 2024-08-23 01:08:56

具有长轮询的 Ajax 是一个简单的解决方案,jquery 和任何其他主要 js 框架中都有插件可以帮助您做到这一点。

Ajax with long polling is a easy solution, there are plugins in jquery and any other major js framework to help you do this.

相思碎 2024-08-23 01:08:56

对于此类问题,Node.js 似乎是一个非常不错的解决方案。 (对于生产来说仍然有点游戏性,但仍然很酷)。对于这样的东西来说,PHP 是一个可怕的环境,你必须改变服务器与请求交互的方式,因为你不再立即响应。 Python 有一些像 Twisted 这样的服务器非常适合这样做,因为它们让您成为服务器。无论您用什么语言编写它,都必须更改典型的请求/响应模型。 (Glassfish 的 Grizzly Comet 服务器为 Java 执行此操作作为示例)

Node.js seems like a pretty sweet solution for stuff like this. (Still a little gamey for production but cool all the same). PHP is a horrible environment for stuff like this, you have to change the way the server interacts with requests because you are no longer immediately responding. Python has a handful of servers like Twisted that are great for this because they let you be the server. No matter what language you write it in you've got to alter the typical request/response model. (Glassfish's Grizzly Comet server does this for Java as an example)

灯角 2024-08-23 01:08:56

您应该尝试 Dmitry Koterov 的 Realplexor,它是一个 Comet 服务器,提供 Javascript 和 PHP API。

中提供了英文版 Readme.txt。

You should try Dmitry Koterov's Realplexor, which is a comet server, that provides Javascript and PHP APIs.

Readme.txt in english is provided in the package.

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