I am currently working on a social networking website (Thinkphp + mysql). I want to notify other online users when some users trigger certain conditions, such: send a private message and send a small gift to the other party. Currently, the only method I can think of is to put the message to be sent into Redis and then put it in Act... I am currently working on a social networking website (Thinkphp + mysql). I want to notify other online users when some users trigger certain conditions, such: send a private email and send a small gift to the recipient
The only method I have come up with is:
Put the message to be sent into Redis, and then perform a redis query on the base class of Action. This way, the user will check whether the Redis contains any content for each operation. However, this is not scientific and is a passive query.
Could you please kindly advise? Thank you!
Reply content:
I am currently working on a social networking website (Thinkphp + mysql). I want to notify other online users when some users trigger certain conditions, such: send a private email and send a small gift to the recipient
The only method I have come up with is:
Put the message to be sent into Redis, and then perform a redis query on the base class of Action. This way, the user will check whether the Redis contains any content for each operation. However, this is not scientific and is a passive query.
Could you please kindly advise? Thank you!
Https://github.com/walkor/web-msg-sender
This is definitely what you want, implemented by websocket + workerman.
DEMO:
Page http://workerman.net for sending messages in the background: 3333/
Page http://workerman.net/web-msg-sender.html for the user to receive messages
Principle: After the user opens the page, the browser will automatically send a websocket (the browser supports HTML5 or Flash) connection to the backend server. The backend can hold these connections. When you want to push messages to the browser, write Data to these websocket connections.
Advantages:
- Non-polling, high performance, normal servers can maintain tens of thousands of connections
- Good real-time performance
- Compatible with various browsers including ie6 (the client supports either flash or html5)
1. Round Robin or long polling (this method is generally used. This is the method you mentioned. You can use ajax to continuously request the server to see if there are any new messages)
2. webSocket (the browser must support html5. This allows the server to actively push data .)
3. flash (this method is usually used in web games)
1 round robin
Ask the background every second using ajax
2 persistent connections
Send an ajax request to the background, but the background blocking does not return. If you know that the request is about to time out, you can return the response immediately if you encounter a new message on the way.
3 websocket
The client establishes a connection channel with the server, and the server can send messages to the browser. HTML5 supports the following features:
I think as long as the number of users reaches a certain scale, small companies should adopt third-party push (Aurora push, Baidu cloud push, etc.) for their products.
High equipment and O & M cost if implemented by yourself
SignalR
Too few words in the content. Please describe it in detail
It is too difficult to implement it by yourself. We recommend that you use the GoEasy. Free Web PUSH Service.
You do not need to write code and support all languages. In just a few minutes, you can implement a push function, which is very simple, fast, and reliable.
Http://goeasy.io