简体   繁体   English

PHP、MySql、JavaScript - 将数据从服务器推送到客户端(实时聊天)

[英]PHP, MySql, JavaScript - Pushing data from server to client (Live chat)

I am trying to create a social network with live chat system, so that users can have notification that they have a new message or receive a message after it was sent from another user in real time.我正在尝试创建一个带有实时聊天系统的社交网络,以便用户可以收到通知,告知他们有新消息或收到其他用户实时发送的消息。

I am new to this, I have made front end (div that will hold messages that are fetched from DB, in form of a paragraph) and DB design, but I am not sure what to use for back end.我对此很陌生,我已经制作了前端(div 将以段落的形式保存从数据库中获取的消息)和数据库设计,但我不确定后端使用什么。 My best solution so far is to make Ajax call for every user in every few seconds interval, but this looks like inefficient solution for many registered users.到目前为止,我最好的解决方案是每隔几秒就为每个用户进行一次 Ajax 调用,但对于许多注册用户来说,这看起来是效率低下的解决方案。

I have searched the web and haven't found any good and up-to-date solutions and I would appreciate if someone could share some experience or point me in the right direction.我在网上搜索过,但没有找到任何好的和最新的解决方案,如果有人可以分享一些经验或为我指明正确的方向,我将不胜感激。

Few ways to do it:几种方法可以做到:

websocket (with socketio it's the best) websocket(最好用 socketio)
Server Sent Event Long Pooling Pooling (Ajax) Server Sent Event Long Pooling 池化(Ajax)

The best now is websocket .现在最好的是websocket But you can have some problems if your chat needs to work behind some firewall.但是如果您的聊天需要在某些防火墙后进行,您可能会遇到一些问题。 But the overall perf if you use websocket , you will use something like 80% less resources.但是如果你使用websocket的整体性能,你将使用大约 80% 的资源。

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

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