简体   繁体   中英

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? 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; why not execute all the calls at the same time?

Take a look into curl_multi_exec . It will allow you to send multiple API calls at the same time. 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);
}
}

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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