如何使用PHP和JQuery开发基于Web的XMPP聊天工具? [英] How to develop a web-based XMPP chat facility using PHP and JQuery?

查看:88
本文介绍了如何使用PHP和JQuery开发基于Web的XMPP聊天工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个具有网站访问者和网站管理员之间的聊天功能的网站。

I am looking to develop a website which features a chat facility between a website visitor and the website administrator.

我知道最好的方法是使用XMPP,但是我没有使用它的经验。我正在寻找使用PHP来实现的功能。

I know the best way to do this would be using XMPP, however I have no experience using it. I am looking to implement this using PHP.

我已经下载了XMPPHP,并编辑了一个示例,以便在GMail中向我的Google Chat客户端发送消息。 Google告诉我另一端没有收到消息。

I've downloaded XMPPHP and I edited an example to send a message to my Google Chat client in GMail, but when I reply Google tells me the other end didn't get the message.

到目前为止,最有用的教程是 http://www.ibm.com/developerworks/xml/tutorials/x-realtimeXMPPtt/ 但我不明白为什么需要安装 Openfire,也不想在本地计算机上构建网站。

So far, the most informative tutorial is http://www.ibm.com/developerworks/xml/tutorials/x-realtimeXMPPtut/ but I don't understand why I need to install 'Openfire' nor do I want to build the website on my local machine.

有人可以告诉我我需要什么(更重要的是为什么)设置这个项目,以便我可以开始为其构建代码?

Can somebody please tell me what I need (and more importantly, why) to set up this project so I can start to build the code for it?

推荐答案

从注释到其他答案的判断你为什么,还有一点什么,但是没有给你一个解决方案,因为我在相关侧边栏中看到了很多解决方案。您必须选择正确的人,并且知道为什么,您才能做出有根据的决定。

Judging from comments to other answers I am going tell you why, and a little what, but not give you a solution because I see a ton of solutions in the "Related" sidebar. You will have to pick the right one and by knowing "the why" you will be able to make an educated decision.

要使聊天感觉正确,必须有对响应有些直接。随着时间的流逝,用户会注意到一秒钟的时间延迟,并且会感到不合时宜。要使即时响应或实时响应在浏览器中工作,需要持久的连接,以便在收到新信息时立即显示。

For chat to feel right, there has to be some immediacy to the responses. A one second lag in time will be noticeable to users over time and give a sense of untimeliness. To make immediate or "real time" responses work in a browser requires a persistent connection so that when new information comes in, it immediately shows up.

浏览器中的持久连接是由于HTTP的请求/响应规范,因此比较困难。有一些规范可以使浏览器保持持久连接,但是这些浏览器并不普遍。将来, WebSockets SPDY ,它们都可以在最新版本的Chrome,Safari和FireFox中使用,但IE稍有滞后。

Persistent connections in browsers are difficult due to the request/response specifications of HTTP. There are specifications in work to bring persistent connections to browsers but those browsers are not ubiquitous. In the future persistent connections will be supplied by WebSockets and SPDY, both of which are available in the latest versions of Chrome, Safari and FireFox with IE lagging a bit.

另一种选择持久连接是 XMPP 。 XMPP是用于Jabber聊天客户端的协议。由于它是开源实现,因此已被移植到许多其他用途。存在JavaScript库,使您可以将浏览器连接到XMPP套接字并侦听新消息。我过去看到的方法是将消息发送到Web服务器,然后让Web服务器将新消息告知XMPP服务器,然后将新消息广播给所有用户。但是,这需要使用XMPP服务器,这会增加系统的复杂性。

Another option for persistent connections is XMPP. XMPP is the protocol used for the Jabber chat client. Since it is an open source implementation it has been ported to many other uses. JavaScript libraries exist that allow you to connect a browser to an XMPP socket and listen for new messages. The method I have seen in the past is to send the messages to the web server, and then have the web server tell the XMPP server about the new message which then broadcasts the new message out to all of the users. However, this requires an XMPP server which raises the complexity of system.

大多数用户都没有处于浏览器版本的前沿,因此您将需要能够处理较旧的版本浏览器。大多数替代方案涉及打开与服务器的长期连接,只要有新数据到达,服务器就会响应。以下是在较旧的浏览器中模拟持久连接的方法列表:

Most users are not on the bleeding edge of browser versions so you will need to be able to handle older browsers. Most of the alternatives involve opening a long running connection to the server which responds whenever new data arrives. Here is a list of methods for simulating a persistent connection in older browsers:


  • Adob​​e Flash Socket

  • ActiveX HTMLFile(IE)

  • 服务器发送的事件(Opera)

  • 具有多部分编码的XHR

  • 带有长轮询的XHR

  • Adobe Flash Socket
  • ActiveX HTMLFile (IE)
  • Server-Sent Events (Opera)
  • XHR with multipart encoding
  • XHR with long-polling

这些较旧的方法和WebSockets由剑圣

These older methods, and WebSockets, are supported by a library called Juggernaut.

UPDATE Juggernaut已被维护者弃用,这有充分的理由:现代浏览器支持开箱即用的持久连接(当然IE除外) )通过称为服务器发送事件(SSE)的规范进行。向后兼容性现在由polyfills(什么是polyfill?)处理,并作为不推荐使用的便笺,可以将SSE带到旧版浏览器中。

UPDATE Juggernaut has been deprecated by the maintainer, for good reason: modern browsers support persistent connections out of the box (with the exception of IE of course) through a specification called Server-Sent Events (SSE). Backwards compatibility is now handled by polyfills (What is a polyfill?) and as the deprecation post notes, there are a couple of good ones to bring SSE to legacy browsers.

这篇关于如何使用PHP和JQuery开发基于Web的XMPP聊天工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆