如何使用PHP,HTML,jQuery执行实时操作[关闭]

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).

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.

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.

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

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.

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.