Home  >  Article  >  Backend Development  >  PHP sends text messages in batches using different platforms

PHP sends text messages in batches using different platforms

藏色散人
藏色散人Original
2019-09-28 09:35:483178browse

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(&#39;list&#39;,$list[$i][&#39;email&#39;]);
        }

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(&#39;localhost&#39;, 6379);
        $auth = $redis->auth(&#39;*****&#39;);
        $lenth = $redis->llen(&#39;list&#39;);
        for ($i=0; $i < $lenth ; $i++) { 
            $phone = $redis->brpop(&#39;list&#39;,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!

Statement:
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