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
Release: 2016-10-17 09:30:09
Original
1746 people have browsed it

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

crontab

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