Mysql-PHP service android push backend

Source: Internet
Author: User
The problem is as follows: {code...} Then: when the maximum service running time is exceeded, nothing will be returned to the client, and the client prompts a service error. When the maximum network connection time of the client is exceeded, a network error occurs. What I want to achieve now is to insert the database into... the problem is as follows:

In a microblog system, the client calls the PHP service to comment on a microblog. If the database is inserted successfully, it must be pushed to the microblog owner. However, the third-party API used for pushing cannot guarantee that a success or failure signal will be returned quickly. In this way, the comments service will remain waiting and will not send a success signal to the client.

Then:

When the maximum running time of the service is exceeded, nothing is returned to the client. The client prompts a service error.
When the maximum network connection time of the client is exceeded, a network error occurs.

What I want to achieve now is that as long as the database is successfully inserted, a signal is returned, and the push work is done independently. There are several problems:
1. if you use a cron scheduled task + comment to determine whether to push the tag, you need to check the database every second to see if there is any pushed data and then push the data. This puts too much pressure on the database and wastes system resources.
2. If it is distributed, is there a better and more formal method? I feel like I am a Field Army...

Reply content:

The problem is as follows:

In a microblog system, the client calls the PHP service to comment on a microblog. If the database is inserted successfully, it must be pushed to the microblog owner. However, the third-party API used for pushing cannot guarantee that a success or failure signal will be returned quickly. In this way, the comments service will remain waiting and will not send a success signal to the client.

Then:

When the maximum running time of the service is exceeded, nothing is returned to the client. The client prompts a service error.
When the maximum network connection time of the client is exceeded, a network error occurs.

What I want to achieve now is that as long as the database is successfully inserted, a signal is returned, and the push work is done independently. There are several problems:
1. if you use a cron scheduled task + comment to determine whether to push the tag, you need to check the database every second to see if there is any pushed data and then push the data. This puts too much pressure on the database and wastes system resources.
2. If it is distributed, is there a better and more formal method? I feel like I am a Field Army...

Python ssdb is not difficult to create a push queue

In the queue mode, when a push job exists, the push job is first heap into the queue to directly return a successful signal. Rabbitmq is recommended to allow the backend of the queue to complete these time-consuming operations.

With the queue, you can directly convert the time-consuming synchronous operations to asynchronous operations, but after the asynchronous operation, the frontend latency will occur. Therefore, the complete solution should be: After a user initiates a comment, the user writes the Comment Request to the task queue and returns the success message to the client. However, the Comment Request is not actually executed at this time, therefore, when users want to read this comment message, they should read the relevant message from the task queue. If they do not read it, they will pull the message from the DB.

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.