Create array of URLs what you want to use with CURL and send them to multiRequest function. See GET example in article.
So it will end up creating CURL for each of these URLs and making requests. After requests it will return results into $multi_curl_result as array. Then you can use returned data.
<?php
// Add multiRequest function here from article
$select_ids = $db->query("SELECT job_id, tids FROM sent_items");
if ($select_ids->num_rows) {
while($row = $select_ids->fetch_object()) {
$records[] = $row;
}
$select_ids->free();
}
if(!count($records)) {
echo 'No records';
} else {
$curls = array();
foreach ($records as $r) {
$curls[] = "http://api.mvaayoo.com/apidlvr/APIDlvReport?user=USER ID:PASSWORD&tid=$r->tids&jobid=$r->job_id";
}
$multi_curl_result = multiRequest($curls);
}
You could add ID to CURL job. Then you can get data from results array by ID.
$curls[$r->job_id] = "http://api.mvaayoo.com/apidlvr/APIDlvReport?user=USER ID:PASSWORD&tid=$r->tids&jobid=$r->job_id";
Now you know which data belongs to which job. For example if job_id would be 10, then this job's data is in $multi_curl_result[10].
Some comments on how multiRequest function works
multiRequest function (source).
function multiRequest($data, $options = array()) {
// array of curl handles
$curly = array();
// data to be returned
$result = array();
// multi handle
// Allows the processing of multiple cURL handles asynchronously.
$mh = curl_multi_init();
// loop through $data and create curl handles
// then add them to the multi-handle
foreach ($data as $id => $d) {
// Create new CURL handle and add it to array
// $id makes it possible to detect which result belongs to which request
$curly[$id] = curl_init();
// If $data item is array, get URL from array, otherwise item should be URL (for GET requests)
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
// Set regular CURL options
curl_setopt($curly[$id], CURLOPT_URL, $url);
curl_setopt($curly[$id], CURLOPT_HEADER, 0);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
// If $data item is array, then we could have POST data
if (is_array($d)) {
// If item has POST data
if (!empty($d['post'])) {
// Set POST data
curl_setopt($curly[$id], CURLOPT_POST, 1);
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
}
}
// Set extra CURL options from array
if (!empty($options)) {
curl_setopt_array($curly[$id], $options);
}
// Add normal CURL handle to a CURL multi handle
curl_multi_add_handle($mh, $curly[$id]);
}
// execute the handles
// $running will have value, if CURL is still running
// Every execute will change it, until all requests has been done
$running = null;
do {
curl_multi_exec($mh, $running);
} while($running > 0);
// Add request responses to array
// Recognizable by $id
foreach($curly as $id => $c) {
// Return the content
$result[$id] = curl_multi_getcontent($c);
// Removes CURL handle ($c) from multi handle ($mh)
curl_multi_remove_handle($mh, $c);
}
// All done
curl_multi_close($mh);
return $result;
}