php用差别平台批量发短信的要领
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缓存中
引荐:《PHP教程》
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触发敕令。直接背景实行。
以上就是php用差别平台批量发短信的细致内容,更多请关注ki4网别的相干文章!