This is a SMS DLR application from http://www.smsgatewaycenter.com which is sent by them to my client's url and I need to configure for my client the same from my client's url to his reseller's url. This script uses every 1 hour to post data to my client's reseller/customer. So, it piles up with thousands of report to send.
I am trying to send dataset which is more than 10000 looped rows using curl. I have tried with curl_multi_exec
and curl_setopt_array
. No matter what, it sends out one by one which is causing load on server. Is there a way, where I can send/forward set of desired request
what i have tried so far for curl_multi_exec
$query = $db->execute("SELECT * FROM `dlr_tbl` WHERE `fetched` = '0'");
$row = $query->getrows();
for($i=0;$i<count($row);$i++) {
$extid = $row[$i]['external_id'];
$status = $row[$i]['delivery_status'];
$cause = $row[$i]['cause'];
$mobile = $row[$i]['mobile_no'];
$date = $row[$i]['delivery_date'];
$requestarray = "externalId=".$extid."&status=".$status."&cause=".$cause."&phoneNo=".$mobile."&date=".$date;
$furl = "http://www.example.com/library/getresponse.php?".$requestarray;
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $furl);
curl_setopt($ch1, CURLOPT_HEADER, 0);
$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch1);
$active = null;
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);
}
}
curl_multi_remove_handle($mh, $ch1);
curl_multi_close($mh);
}
and for curl_setopt_array
$query = $db->execute("SELECT * FROM `dlr_tbl` WHERE `fetched` = '0'");
$row = $query->getrows();
for($i=0;$i<count($row);$i++) {
$extid = $row[$i]['external_id'];
$status = $row[$i]['delivery_status'];
$cause = $row[$i]['cause'];
$mobile = $row[$i]['mobile_no'];
$date = $row[$i]['delivery_date'];
$requestarray = "externalId=".$extid."&status=".$status."&cause=".$cause."&phoneNo=".$mobile."&date=".$date;
$furl = "http://www.example.com/library/getresponse.php";
$ch = curl_init($furl);
curl_setopt_array($ch, array( CURLOPT_URL => $furl, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $requestarray ));
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
}
Is there a better way to do this for multiple rows or should I stick with it?
And also, smsgatewaycenter.com sends the data, the same way... but they send in multiple, more than 50,000 rows gets dumped into mysql table in less time. Where as my code takes a lot of time.
Please suggest or recommend the better way.
Thanks in advance.