I am looking to develop a website which features a chat facility between a website visitor and the website administrator.
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.
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.
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.
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.
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:
These older methods, and WebSockets, are supported by a library called Juggernaut.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With