Php+redis Message Queuing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.