Home  >  Article  >  Backend Development  >  Cache - How does php monitor the redis queue in the background to see if it has a value and execute the script if it has a value? How does php monitor the redis queue in the background to see if it has a value and execute the script if it has a value?

Cache - How does php monitor the redis queue in the background to see if it has a value and execute the script if it has a value? How does php monitor the redis queue in the background to see if it has a value and execute the script if it has a value?

WBOY
WBOYOriginal
2016-10-17 09:30:091692browse

How does PHP monitor whether the redis queue has a value in the background and execute the script if there is a value?

Reply content:

How does PHP monitor whether the redis queue has a value in the background and execute the script if there is a value?

<code class="php">$idle = 0;
$maxWait = 10;
$interval = 50; //50ms
while(true) {
if($redis->lLen() > 0 ) {
     $idle = 0;
    //doing some things
    continue;
}
 //这里很重要
 usleep($interval * ($idle % $maxWait));
 $idle++;
}</code>

crontab

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