您的位置:首页 > 数据库 > Redis

php使用redis的批量发送短信

2017-02-09 11:04 351 查看
1.首先将需要发送信息的手机号存入redis缓存

$redis = new \redis();
$conn = $redis->connect('localhost', 6379);
$auth = $redis->auth('*****'); //redis设置了密码,需要认证
$list = Testuser::find()->asarray()->all();
for ($i=0; $i < count($list); $i++) {
$redis->lpush('list',$list[$i]['email']);
}


将所需发送的手机号存入到redis缓存中

2.调用短信接口发送短信

$redis = new \redis();
$conn = $redis->connect('localhost', 6379);
$auth = $redis->auth('*****');
$lenth = $redis->llen('list');

for ($i=0; $i < $lenth ; $i++) {
$phone = $redis->brpop('list',1,60);//从结尾处弹出一个值,超时时间为60s
$phonenumber = $phone[1];
$sendmsg = send($phonenumber);

if($sendmsg){
//处理发送成功的逻辑
}else{
//处理发送失败的逻辑
}
usleep(500000);//微秒,调用第三方接口,需要注意频率,
}


这里结合php的cli模式,通过函数exec触发命令。直接后台执行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: