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

PHP sends text messages in batches using different platforms

藏色散人
Release: 2023-02-25 11:00:01
Original
3194 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(&#39;list&#39;,$list[$i][&#39;email&#39;]);
        }
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(&#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);//微秒,调用第三方接口,需要注意频率,
        }
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