简体   繁体   English

jquery与PHP mySQL聊天

[英]jquery Chat with PHP mySQL

I set myself a challenge today to write a jQuery chat in under half an hour. 今天我给自己设置了一个挑战,在半小时内写一个jQuery聊天。 It eventually took me 40 minutes. 它最终花了我40分钟。

However, I want to improve it so the load on the server and browser isnt horrendous. 但是,我想改进它,因此服务器和浏览器的负载并不可怕。

Currently the user types into a text box, presses enter, this data is sent to a .php file which updates a mySQL table and outputs all the rows on the table. 目前用户键入文本框,按回车键,此数据被发送到.php文件,该文件更新mySQL表并输出表中的所有行。

There is a set Interval on the div every two seconds to update if anyone said anything without the user pressing enter. 如果有人在没有用户按回车的情况下说了什么,那么每两秒就会在div上设置一个Interval来更新。

I just wanted to know thoughts on how to do perform this in a better way, or the most efficient way. 我只是想知道如何以更好的方式或最有效的方式执行此操作。 I want to understand the best technology to use and why. 我想了解使用的最佳技术和原因。

Thanks for all your input, I love stack overflow, its been invaluable to me. 感谢您的所有输入,我喜欢堆栈溢出,这对我来说非常宝贵。

Using ajax polling for a chat application with the "php back"/"javascript front" technology stack will inevitably result in a heavy server load. 使用“php back”/“javascript front”技术堆栈对聊天应用程序进行ajax轮询将不可避免地导致服务器负载过重。 Http is just not designed for that kind of communication, and if you're using apache (as I assume) there is a really heavy overhead for each request. Http并不是为那种通信而设计的,如果你使用的是apache(正如我所假设的那样),每个请求的开销都非常大。

As some of the commments indicated, you could investigate using a full stack javascript framework (ie Node.js on the backend). 正如一些提交所示,您可以使用完整堆栈的JavaScript框架(即后端的Node.js )进行调查。

When I had the task of accelerating an existing chat application with php backend and Javascript frontend (using periodic ajax poll), I ended up using a 3rd party server side product to handle lightweight XMPP requests. 当我有使用php后端和Javascript前端(使用定期ajax轮询)加速现有聊天应用程序的任务时,我最终使用第三方服务器端产品来处理轻量级XMPP请求。 This server side product was OpenFire , but you could use eJabberd for even better performance - OpenFire is easier to set up and maintain though. 这个服务器端产品是OpenFire ,但您可以使用eJabberd获得更好的性能 - 但OpenFire更易于设置和维护。 The results were more than satisfactory, server load dropped significantly, and messages were delivered instantly for ~1000 online users chatting wildly away (on a less-than-average performance dedicated linux box). 结果非常令人满意,服务器负载显着下降,并且消息立即传送给大约1000名在线用户疯狂地聊天(在一个不太平均的性能专用linux盒子上)。

It's hard to explain all the tiny details within a SO answer's scope, but luckily Ben Werdmuller @ IBM went out of his way to write an awesome tutorial on this topic. 在SO答案的范围内很难解释所有微小的细节,但幸运的是Ben Werdmuller @ IBM不遗余力地撰写了一篇关于这个主题的精彩教程

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

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