Home  >  Article  >  Backend Development  >  laravel5.1 - How to open a process in the php background to monitor Redis queue messages? Use while?

laravel5.1 - How to open a process in the php background to monitor Redis queue messages? Use while?

WBOY
WBOYOriginal
2016-07-06 13:53:212021browse

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?

Reply content:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn