PHP redis 群发短信

时间:2023-03-09 20:29:34
PHP redis 群发短信
$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);//微秒,调用第三方接口,需要注意频率,
}