使用erlang实现Comet并将其用于PHP应用程序

发布于 2024-08-16 06:28:47 字数 659 浏览 4 评论 0原文

我正在构建一个 PHP Web 应用程序,并且我已经达到了需要构建 Comet 服务器的程度,因为每当有新数据可用时我都需要更新我的用户(与 FB 非常相似)。我花了很多时间在网上搜索,我得出的结论是构建 Comet 服务器的最佳方法是使用 erlang 构建它。我还发现 apache-php 并不是一个很好的组合,因为每个请求的进程问题。所以,我必须为 comet 应用程序构建一个轻量级的 http 服务器。

我是 erlang 世界的新手,但我正在考虑在 erlang 中实现 Comet 服务器,并使其充当仅更新客户端的接口。对于我的 Web 应用程序的其余功能,我仍然想继续使用 PHP 来实现它们。因此,将更新客户端的请求定向到 erlang 服务器,并将其他请求定向到 apache-php 服务器。

看起来非常复杂。我需要知道为了构建 Comet 服务器而学习 erlang 的最佳方法是什么,以及如何将两种语言(erlang 和 php)结合起来一起工作,就像我有新信息一样。为了推送给客户,我需要让 Comet 可以使用新的更改,然后它将信息推送给用户。那么我怎样才能从 php 和 erlang 中受益并让它们一起工作呢?

很抱歉这么长的解释,但我真的需要你们的帮助以及你们可能给我的任何指导来学习和实现我想要的东西。预先非常感谢。

编辑: 我是否应该考虑学习 Python 和 Twisted 来实现我想要的目标?

I'm building a PHP web application and I've reached a point that I need to build a Comet server because I need to update my users' whenever a new data is available (pretty much like FB). I've spent so much time searching the web and I've come to a conclusion that the best way to build Comet server is to build it with erlang. Also I've found that apache-php is not a good combination for doing that because the process per request issue.So, I have to build a lightweight http server for comet application.

I'm totally newbie in erlang world but I'm thinking of implementing Comet server in erlang and make it to function as interface for updating the clients only. For the rest of my web application functions, I still want to continue implementing them with PHP. So directing the requests of updating the clients to the erlang server and directing the other requests to apache-php server.

It seems very complicating. I need to know what's the best way to learn erlang for the sake of building Comet server and how to combine the two languages (erlang and php) to work together like when I have new info. to be pushed to the clients, I need to make the new changes available to Comet and then it pushes the info to the users. So how can I benefit from php and erlang and make them work together.

Sorry for the long explanation but I really need your help guys and any guidance you may give me to learn and implement what I want. Thanks a lot in advance.

EDIT:
Should I consider learning Python and Twisted to accomplish what I want?

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

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

发布评论

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

评论(7

花辞树 2024-08-23 06:28:47

用 Erlang 绝对可以做到这一点。一种可能是使用长轮询,您可以使用 mochiweb 来实现。 http://code.google.com/p/mochiweb/

另一个想法是使用插座。在相当数量的浏览器支持 Web 套接字之前,您必须使用 Flash“桥”来创建 TCP 连接,并使用 javascript 与服务器进行通信。看一下 web socket JS: http://github.com/gimite/web-socket- 一旦完成此设置,您就可以在 Erlang 进程和 PHP 之间进行通信,

如下所示: http://www.math-hat.com/~zukerman/projects/php-erlang/

话又说回来,如果你还是 Erlang 的新手,也许你从长远来看,使用 Python 和 Twisted 或 Tornado 会节省时间。

It's definitely possible to do this with Erlang. One possibility would be to use long polling, which you can do with mochiweb. http://code.google.com/p/mochiweb/

Another idea is to use sockets. Until web sockets are supported by a reasonable number of browsers, you'll have to use a flash "bridge" to create a TCP connection, and use javascript to communicate with the server. Take a look at web socket JS: http://github.com/gimite/web-socket-js

Once you have this set up, you can communicate between your Erlang processes and PHP with something like this: http://www.math-hat.com/~zukerman/projects/php-erlang/

Then again, if you're still a newbie to Erlang, maybe you'll save time in the long run with Python and Twisted or Tornado.

半城柳色半声笛 2024-08-23 06:28:47

对于彗星风格的应用程序来说,Apache+php确实是一个糟糕的技术。不过,您可以使用许多其他更接近 php 的技术:RubyPython 和 Perl 都应该可用。如果你真的愿意,你也可以用 php 编写某种套接字服务器,但我可能不会打赌它能成功。这并不是说 Erlang 不是一个好的选择,但还有更主流的选择。

如果您不想使用主流语言,请务必查看 node.js,它运行一些非常令人印象深刻的基准。另外,您可能已经了解一些 javascript。

Apache+php is indeed a bad technology for comet style applications. You can use a lot of other technologies that are closer to php though: Ruby, Python and Perl should all be usable. If you really want, you could probably write some kind of socket server in php aswell, but I would probably not bet on getting it to work out. That's not to say that Erlang isn't a good choice, but there are more mainstream alternatives.

If you don't want to use a mainstream language, be sure also to check out node.js, which runs some very impressive benchmarks. Plus you may already know a bit of javascript.

转身泪倾城 2024-08-23 06:28:47

你可以很快学会 Erlang,你应该能够使用诸如 gen_server、gen_event 之类的 OTP 之类的东西。学习 Erlang 的最快方法应该是阅读以下文档和示例: http:// /www.erlang.org/doc/index.html

对于 PHP 和 Erlang 之间的通信,您可以在 PHP 端使用套接字、fsockopen() 和其余部分,在 Erlang 端使用 gen_tcp。您可以解析从 PHP 端通过管道发送的 Erlang 术语(更多信息此处)。

我从未使用过 Erlang 和 PHP,但我使用 Erlang 和 Python 取得了一些成功,知道 PHP 应该很容易,只需尝试保持一切干净并保持 Erlang 端的状态,仅使用 PHP 来生成 UI。

You can learn Erlang pretty quickly, you should be able to use things like gen_server, gen_event and that sort of thing from OTP. The quickest way to learn Erlang should be to work your way through the documentation and examples at: http://www.erlang.org/doc/index.html.

For the communication between PHP and Erlang you can use sockets, fsockopen() and the rest on the PHP side and gen_tcp on the Erlang side. You can parse the Erlang terms sent trough the pipe from the PHP side (more info here).

I never used Erlang and PHP but I used Erlang and Python with some success, knowing PHP it should be pretty easy, just try to keep everything clean and keep the state on the Erlang side, using PHP only to generate the UI.

白昼 2024-08-23 06:28:47

如果您正在考虑使用 Python 和 Twisted,您可以看看 Orbited。他们有非常成熟的 Comet 实现。您可以使 Orbited 通过 STOMP 协议与您的 PHP 应用程序进行通信。

这篇文章有一个不错的教程,可以帮助您开始使用 Orbited
http://thingsilearned.com/2009 /06/09/starting-out-with-comet-orbited-part-1/

要将您的应用程序与 PHP 集成,您需要在 google 上搜索 PHP STOMP 客户端

If you are considering Python and Twisted you can take a look at Orbited. They have very mature Comet implementation. You can make Orbited to communicate with your PHP application through STOMP protocol.

This article has a decent tutorial which will get you started with Orbited
http://thingsilearned.com/2009/06/09/starting-out-with-comet-orbited-part-1/

To integrate your application with PHP you will need to google for PHP STOMP clients

请别遗忘我 2024-08-23 06:28:47

另一个选项是使用 Nginx 及其推送模块 (http://pushmodule.slact.net/)

这将允许您从 PHP 使用 Comet,而无需学习新语言。

An addtional option is to use Nginx and it's push module (http://pushmodule.slact.net/)

This will allow you to use Comet from PHP without the need to learn a new language.

独自唱情﹋歌 2024-08-23 06:28:47

您应该查看雅司病。它是一个 Erlang Web 服务器,已经存在了十多年,非常稳定,并且仍在积极开发和维护中,并且支持长轮询、PHP 应用程序、WebSocket 等等 - 几乎您想要的一切。

Yaws 源代码位于 github 上,其邮件列表为 此处

You should look into Yaws. It's an Erlang web server that's been around for over a decade, is extremely stable and still under active development and maintenance, and supports long-polling, PHP applications, WebSockets, and much much more — pretty much everything you could want.

The Yaws sources are on github and its mailing list is here.

滥情空心 2024-08-23 06:28:47

尝试一下 Chicago Boss 框架这里 ...使用它你不必知道所谓的东西的具体细节OTP(实际上非​​常简单,强大且经过战斗证明),因为Chicago Boss的设计者成功地封装了它......根据教程。

在学习 OTP 之后,我现在正在学习它。

Try Chicago Boss framework here ... using that you don't have to know the nuts and bolts of the thing called OTP (which actually very easy, powerful and battle proved), because the designer of Chicago Boss, managed to encapsulate it nicely... according to the tutorial.

I'm learning it right now, after learning OTP.

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