实时 HTML/AJAX/PHP 聊天的最佳方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15106745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way for real-time HTML/AJAX/PHP chat
提问by xwinus
I have to create a little AJAX chat in my web application and I'm dealing with problem of real-time communication between javascript client and PHP server. I want my js client to be able to catch new messages from the server as quick as possible. My first idea was to create AJAX request for example each 5 sec. to see whether there are new messages. However, I'm not sure what happens if my application use for example 1000 people, it must be huge load to Apache httpd. I also know about technique called 'long-polling' request, but when I tried that locally on my server, I've completely shooted down my Apache (I've read sth about problems with apache and long-polling). The next way I know about is WebSocket. However, is it true that I have to be able to open port on webserver to use it? Because on regular web hosting, I thing it's not possible and I cant change any Apache/PHP settings on my hosting. Do you have any suggestions how to solve it?
我必须在我的 web 应用程序中创建一个小的 AJAX 聊天,我正在处理 javascript 客户端和 PHP 服务器之间的实时通信问题。我希望我的 js 客户端能够尽快从服务器捕获新消息。我的第一个想法是例如每 5 秒创建一次 AJAX 请求。查看是否有新消息。但是,我不确定如果我的应用程序使用例如 1000 人会发生什么,这对 Apache httpd 来说一定是巨大的负载。我也知道一种叫做“长轮询”请求的技术,但是当我在我的服务器上本地尝试它时,我已经完全拒绝了我的 Apache(我已经阅读了一些关于 apache 和长轮询的问题)。我知道的下一个方法是 WebSocket。但是,我必须能够在网络服务器上打开端口才能使用它,这是真的吗?因为在常规的网络托管上,我认为这是不可能的,我无法更改主机上的任何 Apache/PHP 设置。你有什么建议如何解决吗?
Thank you and excuse my english please, I'm not native.
谢谢你,请原谅我的英语,我不是本地人。
回答by xwinus
It is real time comments system. You can use it as chat Real time chat
这是实时评论系统。您可以将其用作聊天 实时聊天
回答by George Violaris
You should use php comet and push from the server instead of doing requests.
您应该使用 php comet 并从服务器推送而不是执行请求。

