Message Queue-how to implement php asynchronous task queue-php Tutorial

Source: Internet
Author: User
When developing a microblog-like system and using the push mode, a user needs to save a microblog in the "inbox" of all its fans. if the number of followers is large, the processing process is time-consuming. I want to implement this logic using asynchronous queues. The idea is as follows: 1) every time a user posts a microblog... when developing a microblog-like system and using the push mode, a user needs to save a microblog in the "inbox" of all its fans. if the number of followers is large, the processing process is time-consuming. I want to implement this logic using asynchronous queues.

The idea is as follows:
1) each time a user sends a microblog, an asynchronous task is generated and pushed to the queue.
2) the tasks in the queue are executed sequentially by another process or thread.

The problem is:
MemcachedQ and starling can be used to implement message queues. it is no problem to put tasks in message queues in a certain format.
But how can I enable another process or thread to retrieve the tasks in the queue and execute them?
Write a php loop to retrieve tasks in the queue? If there is no task, the query is directly cyclically performed? Is there a better solution?

Reply content:

When developing a microblog-like system and using the push mode, a user needs to save a microblog in the "inbox" of all its fans. if the number of followers is large, the processing process is time-consuming. I want to implement this logic using asynchronous queues.

The idea is as follows:
1) each time a user sends a microblog, an asynchronous task is generated and pushed to the queue.
2) the tasks in the queue are executed sequentially by another process or thread.

The problem is:
MemcachedQ and starling can be used to implement message queues. it is no problem to put tasks in message queues in a certain format.
But how can I enable another process or thread to retrieve the tasks in the queue and execute them?
Write a php loop to retrieve tasks in the queue? If there is no task, the query is directly cyclically performed? Is there a better solution?

Consider redis subscribe
Http://redis.io/topics/pubsub

This is the push id.

I have seen a fastcgi_finish_request dependent on nginx.
After the call. Php continues.

Refer to this php-resque
Https://github.com/chrisboulton/php-resque
Task Queue

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.