Laravel5.1-how does one set up a process in the php background to listen to Redis queue messages? Use while?

Source: Internet
Author: User
I know that the Redis list has the pubsub mode, but how can I enable a process in the php background to listen to the Redis queue messages? Is a while loop used? Isn't that good? I know Redis list has pub/sub mode, but how can I enable a process in the php background to listen to Redis queue messages? Is a while loop used? Isn't that good?

Reply content:

I know that the Redis list has the pub/sub mode, but how can I enable a process in the php background to listen to the Redis queue messages? Is a while loop used? Isn't that good?

while($res = Redis::blpop($key)) {    doJob($res);}

Redis has a blocking primitive to read the queue. when the queue has no data, the php listening process suspends.

While + sleep no problem

$ Cmd = "ps aux | grep-I '". $ task_name. "'| grep-v grep | wc-l"; if (shell_exec ($ cmd)> 0) {echo "[$ task_name] The process is running... \ R \ n "; return false ;}

Use the pcntl_fork series to enable the daemon and listen for requests.
An operation in the redis queue is to send a request to the listening port and process the historical failed message queue.

Thank you. I have not done any related practices.
I just searched for it: there are many resque
1) http://www.cnblogs.com/zl0372/p/3696641.html
2) http://avnpc.com/pages/run-background-task-by-php-resque
Hope to help you

It is good to mount a process on the server background for monitoring. the supervisor will automatically restart even if it fails.

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.