index.php Current Queue condition
$redis=new Redis (); $redis->connect (' 127.0.0.1 '); $ret=$redis->lrange (' Test ', 1,1000); Var_dump ($ret);
Push.php in the queue
$redis=NewRedis ();$redis->connect (' 127.0.0.1 '); for($i= 0;$i<50;$i++){ $redis->lpush (' Test ',$i);}Echo' <script>window.settimeout (function () {location.href= "http://localhost/mq/";},2000);</script> ';Ob_flush();Flush();//No bufferingfile_get_contents(' http://localhost/mq/pop.php ');
Pop.php out of the team
Set_time_limit(0); $redis=NewRedis ();$redis->connect (' 127.0.0.1 '); while(true){ $ret=$redis->lpop (' Test '); if($ret!==false){ Echo $ret.‘ <br> '; Ob_flush();Flush();//No buffering Sleep(1); } Else{ Exit('--------End--------'); } }
Executes the push.php Insert queue and calls the pop.php processing queue.
Automatically goes to index.php after 2 seconds without waiting for the task to finish.
Even if you close the browser to reopen index.php, you can still see that the queue has been processed in the background.
Php+redis Message Queuing