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

WBOY
Release: 2016-07-06 13:53:21
Original
2038 people have browsed it

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>
Copy after login

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>
Copy after login

<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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template