简体   繁体   English

如何在PHP MySQL中将批量短信发送到手机号码

[英]how to send bulk sms to mobile numbers in php mysql

How can I send a message to more than 50 mobiles at a time? 如何一次向50多个手机发送消息? The code below will execute but it takes a long time. 下面的代码将执行,但是需要很长时间。

<?php
    $sqljobseekers=$con->query("SELECT * FROM users");
    $y=mysqli_num_rows($sqljobseekers);

    while($jobseekers=$sqljobseekers->fetch_assoc()) {
       $seekermobile=$jobseekers['emp_mobile'];
       $msg="Dear Candidate, .".$job_cmp_name.". is looking .".$jobrolename.". like u, for more details logon www.venkymama.com / www.lifemadeeasyglobal.com";
       $msg=urlencode($msg);
       $sms_file="http://tra.bulksmshyderabad.co.in/websms/sendsms.aspx?userid=$user&password=$password&sender=atmm&mobileno=".$seekermobile."&msg=$msg.";    
       $sms_h=fopen($sms_file,"r");
       fclose($sms_h);
    }    
?>

Instead of looping through your users, making an API call, waiting for a response, and moving onto the next user; 而不是遍历用户,而是进行API调用,等待响应并转移到下一个用户; why not execute all the calls at the same time? 为什么不同时执行所有调用?

Take a look into curl_multi_exec . 看一下curl_multi_exec It will allow you to send multiple API calls at the same time. 它将允许您同时发送多个API调用。 Something similar to this: 类似于以下内容:

<?php
    $sqljobseekers=$con->query("SELECT * FROM users");
    $y=mysqli_num_rows($sqljobseekers);

    $mh = curl_multi_init();
    while($jobseekers=$sqljobseekers->fetch_assoc()) {
       $seekermobile=$jobseekers['emp_mobile'];
       $msg="Dear Candidate, .".$job_cmp_name.". is looking .".$jobrolename.". like u, for more details logon www.venkymama.com / www.lifemadeeasyglobal.com";
       $msg=urlencode($msg);
       $sms_file="http://tra.bulksmshyderabad.co.in/websms/sendsms.aspx?userid=$user&password=$password&sender=atmm&mobileno=".$seekermobile."&msg=$msg.";    
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $sms_file);
       curl_multi_add_handle($mh, $ch);
    }

$active = null;
//execute the handles
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
            $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM