comet 如何与 php 一起工作?
当我使用 comet iframe 时,我只是将脚本标签从后端 php 文件发送到前端,并且 javascript 正在显示它。
有人可以简要解释一下彗星服务器在图片中出现的位置以及前端(javascript)、后端(php)和彗星服务器之间的通信方式。
因为我读到,如果您打算让很多用户使用您的 comet 应用程序,那么最好有一个 comet 服务器。但我不太明白这些部分之间的耦合。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用此链接:
http://www.zeitoun.net/articles/comet_and_php/start
这是我能找到的最好的教程,需要 1 分钟来尝试;
简而言之:
(该教程中的图片)
索引,可以是 html 或 php,创建一个请求,当有人向您发送消息时,只有通过聊天发送回数据后,php 才会回复该请求。
如果您有很多用户聊天,我建议使用 java 聊天应用程序,
否则您的服务器将加载正在运行的 php 引擎(每个未应答的请求都会使 php 引擎保持活动状态,这就是服务器容量)。
http://streamhub.blogspot.com/2009/07/ tutorial-building-comet-chat.html
这应该可以帮助你解决这个问题,但是你确实需要java托管:)
玩得开心
编辑:
只需阅读其他服务器部分;向自己的服务器发送请求可能会变得混乱,因为超时功能可能无法正常工作,因此服务器崩溃,独立的服务器在一定时间后使连接超时,无论如何。
use this link:
http://www.zeitoun.net/articles/comet_and_php/start
That is the best tutorial i could found, and takes 1 min to try;
in short:
( image from that tutorial )
index, can be html or php, creates a request, which php doesnt answer until there is data to send back, with chat, when someone sends you a message.
If you have many users chatting, i recommend using a java chat app
otherwise your server will load up with running php engines ( each unanswered request keeps a php engine alive, which is server capacity ).
http://streamhub.blogspot.com/2009/07/tutorial-building-comet-chat.html
this should help you out with that, but you do need java hosting :)
have fun
edit:
just read the other server part; sending requests to your own server can get messed because the timeout function may not work well, so the server crashes, an independant server timeouts the connection after a certain amount of time, no matter what.
我这里有一个非常简单的例子,可以帮助您开始使用 comet。它涵盖了使用 NHPM 模块编译 Nginx,并包含 jQuery、PHP 和 Bash 中简单发布者/订阅者角色的代码。
http://blog.jamieisaacs.com/2010/ 08/27/comet-with-nginx-and-jquery/
可以在此处找到工作示例(简单的聊天):
http://cheetah.jamieisaacs.com/
I have a very simple example here that can get you started with comet. It covers compiling Nginx with the NHPM module and includes code for simple publisher/subscriber roles in jQuery, PHP, and Bash.
http://blog.jamieisaacs.com/2010/08/27/comet-with-nginx-and-jquery/
A working example (simple chat) can be found here:
http://cheetah.jamieisaacs.com/