Long-Polling web chat application with PHP, MySQL and jQuery

We use a chat system in our company that is built in Ajax, PHP and jQuery. It currently refreshes every second, both at the admin end and at the user end, to fetch data from mysql. This makes the system inefficient and slow.

I want to fetch data from mysql only when user or admin post post. But the problem is this: how will I check from the administrator that the user is sending a message (in real time)? Is it possible in Ajax to send data / request 2 different PHP pages at the same time in real time? This might be the solution.

Or any idea to create an effective chat system? We don't want to use a third party chat solution. Any idea / help would be much appreciated.

Thanks,
Rejoanul Alam

+3


source to share


2 answers


jQuery Long Polling

This is possible with jQuery / PHP / MySQL with long polling. Sample implementation available at this url: http://sugunan.com/sites/chat/chatterFront.html

Open this in two different browsers or machines. And provide a name and start a chat.

The source code of this chat tool can be downloaded from this URL: http://www.sugunan.com/sites/chat/source.zip



Node.js

If you own the server you can go for the implementation node.js

faye

: http://faye.jcoglan.com/node.html

It is a push notification technology. So it won't ping the server often. But it delivers the message instantly. It can be integrated with PHP if you want to save the message to the server.

+3


source


Yes, there are several ways,
They are called comets, sometimes refer to ajax, google it;)



long polling is used on shared hosting,
on dedicated hosts or VPS sockets.

-1


source







All Articles