简体   繁体   English

其他用户收到消息

[英]Other users receive messages

So this is not an error. 因此,这不是错误。 I just don't know how to do this. 我只是不知道该怎么做。 I created a chat application with HTML/JS/PHP and I am storing the messages for each chat in a mysql database. 我使用HTML / JS / PHP创建了一个聊天应用程序,并将每次聊天的消息存储在mysql数据库中。 I am currently using a php script to receive all messages from the database every 0.5 seconds and printing them onto my chat file. 我目前正在使用php脚本,每0.5秒从数据库接收所有消息,并将它们打印到我的聊天文件中。 I wanted to know any better way to receive a message without having to reload or wait. 我想知道任何无需重新加载或等待即可接收消息的更好方法。 Maybe some kind of notification the if a person sent a message then the other users of the chat receive that exact message or some socket thing idk. 也许是某种通知,如果某人发送了一条消息,那么聊天的其他用户会收到该确切消息或某些套接字事物idk。 Any help would be appreciated. 任何帮助,将不胜感激。

I would suggest using WebSockets. 我建议使用WebSockets。 Check this out - https://github.com/Flynsarmy/PHPWebSocket-Chat 检查一下-https: //github.com/Flynsarmy/PHPWebSocket-Chat

Websockets is the best way to do this. Websockets是执行此操作的最佳方法。 This opens a constant connection to the server and the server can push events to the client. 这将打开与服务器的恒定连接,服务器可以将事件推送到客户端。

With php this can be implemented by using another service like Redis or Pusher . 使用php可以通过使用其他服务(例如RedisPusher)来实现。

You can use socket.io 您可以使用socket.io

By using this you don't have to pull the data from the server continuously. 通过使用此功能,您不必连续从服务器提取数据。

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

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