Ask how to implement the webpage private message push function similar to Sina Weibo

Source: Internet
Author: User
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:

  1. Non-polling, high performance, normal servers can maintain tens of thousands of connections
  2. Good real-time performance
  3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.