In my PHP application, I am running curl_exec inside foreach loop.
$myarray = array('0'=>'mobileno.1', '1'=>'mobileno.2'); // Contains 4000 records - from contacts table
foreach($myarray as $myarr)
{
$tomobile = $myarr;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $sms_gateway_url."?username=".$sms_username."&api_password=".$sms_password."&to=".$tomobile."&priority=".$sms_priority."&sender=".$sender_id."&message=".$mes
));
$resp = curl_exec($curl);
curl_close($curl);
if (strpos($resp, "Submitted") !== false)
{
$status = 'success';
}
else
{
$status = 'failed';
}
// mysql insert query (sendsms table)
// mysql update query (contacts table)
}
Here, the logic is for each execution, I will get 4000 unique records from contacts table, and send SMS to each one using foreach loop.
Here the problem is sometimes duplicate SMS are sending for same contacts. For eg, in a single execution, my scripts is sending around 5000 SMS instead of 4000 SMS.
Example: If I send 4000 SMS, more than 5000 SMS have sent and same 5000 rows are inserted in sendsms table. The duplicate count gets varies for every execution. If I hide curl options, 4000 rows are inserted in sendsms table correctly.
json. I suggest you to check those first before get into this