php method to send text messages in batches using different platforms
1. First, save the mobile phone number to which messages need to be sent. Enter the redis cache
$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']); }
Save the mobile phone number to be sent into the redis cache
Recommended: "PHP Tutorial"
2. Call SMS interface sends SMS
$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);//微秒,调用第三方接口,需要注意频率, }
This is combined with the cli mode of php and triggers the command through the function exec. Directly execute in the background.
The above is the detailed content of PHP sends text messages in batches using different platforms. For more information, please follow other related articles on the PHP Chinese website!