$redis = new \Redis(); $redis->connect('127.0.0.1', 6379); $list = M('Sms')->field('phone')->where(array('s'=>0))->select(); ; for ($i=0; $i < count($list); $i++) { $redis->lpush('list',$list[$i]['phone']); } $lenth = $redis->llen('list'); for ($i=0; $i < $lenth ; $i++) { $phone = $redis->brpop('list',1,60);//从结尾处弹出一个值,超时时间为60s $phonenumber = $phone[1]; //$sendmsg = send($phonenumber); $sendmsg = true; if($sendmsg){ //处理发送成功的逻辑 M('Sms')->where(array('phone' => $phonenumber))->data(array('s' => 1))->save(); $this->writePostLogb($phonenumber); }else{ //处理发送失败的逻辑 } usleep(500000);//微秒,调用第三方接口,需要注意频率, }