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觸發命令。直接后臺執行。
新聞熱點
疑難解答
圖片精選