如何实现真正的快速网络聊天用PHP?如何实现、快速、网络、PHP

2023-09-10 13:19:53 作者:与你未来

如何实现真正的快速网络聊天用PHP?

How to implement a real fast web chat with PHP?

有没有人想过为什么Facebook的聊天就是这么真的快?即使在IE浏览器没有WebSocket的。

Has anybody ever wonder why Facebook chat is just so really really fast? even in IE without WebSocket.

是不是唯一的办法就是给setInterval在JS以检查是否有新的消息?但我觉得它(Facebook的聊天框),就像即时反应。

Isn't the only way is to setInterval in JS to check for new messages? But I feel it (Facebook chat box) like having instant reaction.

如何实现这么大的事与PHP?

How to implement such great thing with PHP?

推荐答案

瞬时聊天,你所描述的,一般来达到的一个被称为长轮询什么的,如果我们在谈论AJAX,彗星(< A HREF =htt​​p://en.wikipedia.org/wiki/Push_technology#Other_technologies>维基百科 会谈的这件事)。轮询趋于紧张的Apache服务器,但也有一些专门的服务器来处理它像 APE 。我不知道,但我认为你可以用 NodeJS 和的 NGINX 处理压力pretty的好。

The instantaneous chat you're describing is generally acheived by a something called "Long Polling" or, if we're talking about AJAX, "Comet" (Wikipedia talks about it). Polling tends to strain Apache servers, but there are some specialized servers to deal with it like APE. I'm not sure but I think you can do the same with NodeJS and NGINX handles the stress pretty well.

这里的是这里一篇关于如何实现用PHP jQuery和AJAX的长轮询聊天。

Here's an article here about how to implement a long polling chat with PHP jQuery and AJAX.

最好的运气,我希望它帮助!

Best of luck, and I hope it helped!