简体   繁体   English

实时HTML / AJAX / PHP聊天的最佳方式

[英]Best way for real-time HTML/AJAX/PHP chat

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. 我必须在我的Web应用程序中创建一个小的AJAX聊天,我正在处理javascript客户端和PHP服务器之间的实时通信问题。 I want my js client to be able to catch new messages from the server as quick as possible. 我希望我的js客户端能够尽快从服务器捕获新消息。 My first idea was to create AJAX request for example each 5 sec. 我的第一个想法是每5秒创建一次AJAX请求。 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. 但是,我不确定如果我的应用程序使用例如1000人会发生什么,它必须是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). 我也知道称为'长轮询'请求的技术,但当我在我的服务器上本地尝试时,我已经完全击落了我的Apache(我已经读过关于apache和长轮询的问题)。 The next way I know about is WebSocket. 我知道的下一个方法是WebSocket。 However, is it true that I have to be able to open port on webserver to use it? 但是,我必须能够在Web服务器上打开端口才能使用它吗? Because on regular web hosting, I thing it's not possible and I cant change any Apache/PHP settings on my hosting. 因为在常规的虚拟主机上,我认为这是不可能的,我无法更改我的主机上的任何Apache / PHP设置。 Do you have any suggestions how to solve it? 你有什么建议怎么解决吗?

Thank you and excuse my english please, I'm not native. 谢谢你,请原谅我的英语,我不是本地人。

It is real time comments system. 这是实时评论系统。 You can use it as chat Real time chat 您可以将其用作聊天实时聊天

You should use php comet and push from the server instead of doing requests. 你应该使用php comet并从服务器推送而不是做请求。

Check out this question also 看看这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM