How to implement real fast web chat with PHP?

How to implement real fast web chat with PHP?

Has anyone ever wondered why Facebook chat just really really really fast? even in IE without WebSocket.

Not the only way to set Interval in JS to check for new messages? But I feel that this (Facebook chat chat) is an immediate reaction.

How to implement such a wonderful thing with PHP?

+6
source share
3 answers

The instant chat you are talking about usually gets what is called "Long Polling", or, if we are talking about AJAX, "Comet" ( Wikipedia talks about this). The survey tends to reconfigure Apache servers, but there are some specialized servers for working with it, such as APE . I'm not sure, but I think you can do the same with NodeJS and NGINX . stress is pretty good.

Here's an article on how to implement a long chat survey with PHP jQuery and AJAX.

Good luck, and I hope this helps!

+7
source

I agree with @ joseph-szymborski, although it would be wise to start looking for WebSocket solutions that return to WebSockets via Flash and / or a lengthy survey.

Here are some relevant SO questions:

If you want to work with PHP or on a shared hosting, I would recommend to see the hosted web solution in real time .

+3
source

You might want to consider Node.js to serve clients in real time, as long polling with PHP / AJAX can put a strain on your server. But implementation itself is a difficult task. Just saying it. Long polling with PHP / AJAX can put a strain on your server.

My typical theoretical implementation of the same:

  • Create a Node.js server to query the database.
  • Send variables and / or session data from php to Node js using cURL.
  • Parse the URL on the Node.js server and use the variables to check for changes to the database.
  • Retrieve new data if changes occur and send to customer.
0
source

Source: https://habr.com/ru/post/901776/


All Articles