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

时间:2016-10-07 06:50:56

标签: php mysql

如何一次向50多部手机发送信息?下面的代码将执行,但需要很长时间。

<?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);
    }    
?>

1 个答案:

答案 0 :(得分:2)

而不是循环用户,进行API调用,等待响应,然后转移到下一个用户;为什么不同时执行所有的电话?

查看curl_multi_exec。它允许您同时发送多个API调用。类似的东西:

<?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);
}
}

?>