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