Ask how to achieve a similar Sina Weibo website private messaging push function

Source: Internet
Author: User
Currently working on a social networking site (thinkphp+mysql), I would like to notify other users of the online user when certain conditions are triggered, such as: Send a private message and send a small gift to each other.

At the moment I think the only way to do this is:
Put the message you want to send into Redis, and then make a Redis query in the action base class so that each time the user does this, it will check if the Redis has content. But this is not very scientific, belong to the passive query.

Ask you all have what good method, thank you very much!

Reply content:

Currently working on a social networking site (thinkphp+mysql), I would like to notify other users of the online user when certain conditions are triggered, such as: Send a private message and send a small gift to each other.

At the moment I think the only way to do this is:
Put the message you want to send into Redis, and then make a Redis query in the action base class so that each time the user does this, it will check if the Redis has content. But this is not very scientific, belong to the passive query.

Ask you all have what good method, thank you very much!

Https://github.com/walkor/web-msg-sender
This is definitely what you want, Websocket+workerman realized.

DEMO:
Page http://workerman.net:3333/for sending messages in the background
Page http://workerman.net/web-msg-sender.html the user receives the message

principle : When the user opens the page, the browser will automatically send a websocket to the backend server (browser support HTML5 or Flash) to connect, the back end hold these connections, when want to push the message to the browser, Write data to these websocket connections.

Advantages :

    1. Non-polling, high performance, the normal server can maintain tens of thousands of connections
    2. Good real-time sex
    3. Compatible with various browsers including IE6 (the client supports Flash or HTML5 any one on the line)

1. Polling or long polling (this is the way it is generally used.) This is the way you say, using AJAX to constantly request the server, see if there is no new messages)
2.webSocket (requires browser support HTML5. This can be implemented by the server proactive push. )
3.flash (This is the way it is in general web games)

1 polling
Use Ajax to query the background for a second
2 Long connections
Sends an AJAX request to the background, but the background block does not return, knowing that it will be timed out before returning, the new message time can be returned immediately
3 WebSocket
Client and server to establish connection channel, the server can proactively send messages to the browser, HTML5 supported features

I think as long as the user to reach a certain scale, small companies do products, this should go three-party push (Aurora push, Baidu Cloud push, etc.) to do, even if the pay
The cost of equipment and operations is high when you implement it yourself.

SignalR

The content is too few words, please describe in detail

Self-realization too troublesome, it is recommended that you use Goeasy. Free web Push service.
You don't have to write code, support all languages, a few minutes to achieve a push function, very simple, fast, but also reliable.
Http://goeasy.io

  • Related Article

    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.