1

I'm developing a kind of a chat for a website and I can't imagine how to start it, for instance, when I use the facebook chat I can see that even if I use two different browsers, the commands work on both. If I go offline using one browser, I can see that the other one goes offline as well.

One more thing how does the guy on the other side is gonna know when I send the message?

P.S.: I know the programing languages mentioned, I just need to know how the chat works in real-time (not the codes, but the idea).

Foreba
  • 410
  • 4
  • 15

5 Answers5

3

In order have a real-time chat like facebook, your server needs to 'push' data to the browser, while ajax is a 'polling' technique.

I use APE Push Engine, but you can also use Socket.IO client side, and Node.js server-side or Comet. Honestly, I would go the Socket.IO or Comet route if I could go back because it has a bigger community / better documentation.

  • That's it... I've tested the chat (APE Push Engine), and that's what I'm looking for... great... – Foreba Jun 06 '12 at 21:55
2

You can try using a technology called Comet.

There are some plugins that integrate this in jQuery, (like this?) but i have only heard of them.

Rodik
  • 4,054
  • 26
  • 49
1

PHP is not the correct tool for the job. You need something which handles different requests in different threads. I used Node.js for this kind of job once. see this tutorial.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

Options are :

  • find a library which supports blocking connection on the server , then the server will return an answer when it has data
  • poll
  • "the old way" ie. get an endless document which just keeps growing and use it to stream the data.
Markus Mikkolainen
  • 3,397
  • 18
  • 21
0

You have to have a main database and a PHP script on the server. You update the browser output with AJAX calls using jQuery.

hm.
  • 166
  • 9
  • Don't you think it'll request so much my MySQL server? For instance, if I have a lot of users accessing the chat at the same time and the script updates 5 to 5 secs. I was thinking about something that could catch the message only if it's new based on the last one. – Foreba Jun 06 '12 at 21:49
  • There a ways to cache the output on the MySQL side as well as on the PHP side. However a MySQL db should be able to take a lot and when your service is really big, you may use a cloud server. Just make sure at the beginning, that you do not choose the cheapest host, where the DBs are overloaded. Better is using your own server, so nobody else eats up the performance. You can also play with the refresh interval. 5 seconds should be reasonable... – hm. Jun 06 '12 at 22:24