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.