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