Message Queuing-How to implement the asynchronous task queue for PHP

Source: Internet
Author: User
In the development of a micro-blogging system, the use of push mode, users send a micro-blog, it is necessary to have this microblog in all of its fans each of the "Inbox" to save one, if the number of fans, the process will be time-consuming, want to use this logic with an asynchronous queue to achieve.

Ideas are as follows:
1) The user generates an asynchronous task for each tweet, pushing it into the queue
2) Execution of tasks in the queue by another process or thread sequence

The problem is:
Implementing Message Queuing can take memcachedq,starling and so on, putting tasks in a format in a message queue it's okay.
But how do you open another process or thread to fetch the tasks in the queue and execute them?
Write a PHP loop to fetch the tasks in the queue? The query is directly circulated without a task? Is there a better solution?

Reply content:

In the development of a micro-blogging system, the use of push mode, users send a micro-blog, it is necessary to have this microblog in all of its fans each of the "Inbox" to save one, if the number of fans, the process will be time-consuming, want to use this logic with an asynchronous queue to achieve.

Ideas are as follows:
1) The user generates an asynchronous task for each tweet, pushing it into the queue
2) Execution of tasks in the queue by another process or thread sequence

The problem is:
Implementing Message Queuing can take memcachedq,starling and so on, putting tasks in a format in a message queue it's okay.
But how do you open another process or thread to fetch the tasks in the queue and execute them?
Write a PHP loop to fetch the tasks in the queue? The query is directly circulated without a task? Is there a better solution?

You can consider Redis's subscribe
Http://redis.io/topics/pubsub

This is a push ID.

Have seen a fastcgi_finish_request that relies on nginx.
After the call. PHP continues to execute.

You can 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.