Home >Backend Development >PHP Tutorial >laravel5.1 - How to open a process in the php background to monitor Redis queue messages? Use while?
I know that the Redis list has a pub/sub mode, but how do I open a process in the PHP background to monitor the Redis queue messages? Use a while loop? Isn’t this bad?
I know that the Redis list has a pub/sub mode, but how do I open a process in the PHP background to monitor the Redis queue messages? Use a while loop? Isn’t this bad?
<code>while($res = Redis::blpop($key)) { doJob($res); }</code>
Redis has a blocking primitive to read the queue. When there is no data in the queue, the PHP listening process will hang
<code>while + sleep 没啥问题</code>
<code>$cmd = "ps aux | grep -i '".$task_name."' | grep -v grep | wc -l"; if(shell_exec($cmd) > 0){ echo "【$task_name】进程运行中…\r\n"; return false; }</code>
Start the daemon process through the pcntl_fork series of methods and listen for requests.
The operation of the redis queue is to send requests to the listening port and process the historical failure message queue at the same time.
Thank you for the invitation. I haven't done any relevant practice.
Just searched: resque is used more often
1)http://www.cnblogs.com/zl0372/p/3696641.html
2)http://avnpc.com/pages/run -background-task-by-php-resque
Hope it helps you
Just hang a process in the background of the server to monitor it. The supervisor will automatically restart even if it hangs