How to create an XMPP web interface using PHP and jQuery?

I am looking for a website development that has a chat between a website visitor and a website administrator.

I know that the best way to do this is to use XMPP, but I have no experience using it. I want to implement this using PHP.

I downloaded XMPPHP and I edited the example of sending a message to the Google Chat client in GMail, but when I reply, Google reports that the other end did not receive the message.

Until now, the most informative tutorial has been http://www.ibm.com/developerworks/xml/tutorials/x-realtimeXMPPtut/ , but I don’t understand why I need to install "Openfire", and I don’t want to create a site on my local the car.

Can someone please tell me what I need (and more importantly why) to set up this project so that I can start building code for it?

+8
php websocket chat xmpp
source share
3 answers

Judging by the comments on the other answers, I’ll tell you why and something like that, but I don’t give you a solution, because I see a lot of solutions in the sidebar. You will need to choose the right one, and knowing why, you can make an informed decision.

In order for the chat to feel right, there must be some immediacy in the responses. The time delay will be noticeable to users over time and will give a sense of timeliness. For immediate or "real" answers to work in the browser, a constant connection is required so that when new information appears, it immediately appears.

Persistent connections in browsers are complicated due to the HTTP / HTTP / request specifications. There are specifications in the work to ensure constant connections with browsers, but these browsers are not ubiquitous. In the future, persistent connections will be delivered by WebSockets and SPDY , both of which are available in the latest versions of Chrome, Safari and FireFox with IE slightly behind.

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

Most users are not on the edge of browser versions, so you will need to handle older browsers. Most alternatives include opening a long connection to a server that responds when new data arrives. The following is a list of persistent connection modeling methods in older browsers:

  • Adobe Flash Socket
  • ActiveX HTMLFile (IE)
  • Server Events (Opera)
  • XHR multi-line coding
  • Long poll XHR

These old methods and WebSockets are supported by the Juggernaut library.

UPDATE Juggernaut is deprecated by its maintainer for a good reason: modern browsers support persistent connections out of the box (with the exception of IE, of course) through the Server-Sent Events (SSE) specification. Backward compatibility is now handled with polyfills ( What is polyfill? ), And as a postrecation post there are some good ones that bring SSE to legacy browsers.

+8
source share
0
source share

Instant messaging applications must be in real time. The website uses the HTTP protocol, which uses a request / response method. One way to do this is to poll. send a request for new pending messages for the user to the server. The server should be able to distinguish between messages that were sent and those that still need to be delivered. this method is called polling. Your browser constantly asks the server to send any pending messages. But this can negatively affect the bandwidth, as well as drain the battery (in case of accessing the website using a smartphone). It is best to use an XMPP server.

0
source share

All Articles