PHP sends text messages in batches using different platforms

藏色散人
Release: 2023-02-25 11:00:01
Original
3064 people have browsed it

PHP sends text messages in batches using different platforms

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']);
        }
Copy after login

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);//微秒,调用第三方接口,需要注意频率,
        }
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!