Reputation: 3
<?php
$mysender2= "";
$myrecepient2= "923336088811,923126812536,923134126153";
$mymessage2 = "this is message";
$api_key = "****";
$api_secret="****";
$to_arr = explode(",", $myrecepient2);
foreach ($to_arr as $b){
$url = "https://rest.nexmo.com/sms/json?" .
"api_key=".$api_key. "&" .
"api_secret=" .$api_secret . "&" .
"from=" . urlencode($mysender2) . "&" .
"to=" . urlencode($b) . "&" .
"text=" .urlencode($mymessage2);
$c = curl_init($url);
// Use SSL
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
$html = curl_exec($c);
curl_close ($c);
}
?>
The above script will run again and again untill the process completed . how to show an echo on process complete .. such as "Your Process Completed"
Upvotes: 0
Views: 100
Reputation: 391
Sorry, but, your script is so bad and your server goes cry, I know that exists 3 calls only, because your array have 3 values, but if you need more? You will have problems.
The best way in your case is a php header refresh with offset, see bellow:
$offset = isset( $_GET['offset'] ) ? $_GET['offset'] : 0; $mysender2= ""; $myrecepient2= "923336088811,923126812536,923134126153"; $mymessage2 = "this is message"; $api_key = "****"; $api_secret="****"; $to_arr = explode( ",", $myrecepient2 ); if( $offset > count( $to_arr ) ) { echo 'Completed!'; } else { $b = $to_arr[ $offset ]; $url = "https://rest.nexmo.com/sms/json?" . "api_key=".$api_key. "&" . "api_secret=" .$api_secret . "&" . "from=" . urlencode($mysender2) . "&" . "to=" . urlencode($b) . "&" . "text=" .urlencode($mymessage2); $c = curl_init($url); // Use SSL curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); $html = curl_exec($c); curl_close ($c); header('Refresh: 0.5; url=YOUR-URL?offset=' . $offset + 1 ); // half a second }
Upvotes: 1