I can't find it in any docs and it doesn't come up when I search for it. I'm trying to follow this tutorial, here's my code so far:
$location_urls = array();
foreach($entity_ids as $url) {
array_push($location_urls, 'https://something.com/api/v1/location/' . $url);
}
$mh = curl_multi_init();
for ($i = 0; $i < count($entity_ids); $i++) {
add_url_to_multi_handle($mh, $location_urls);
}
here's the error i'm getting:
<b>Fatal error</b>: Uncaught Error: Call to undefined function add_url_to_multi_handle() in C:\xampp\htdocs\api_test\example.php:45
Stack trace:
#0 {main}
thrown in <b>C:\xampp\htdocs\api_test\example.php</b> on line <b>45</b><br />
and nothing comes up in for searches in reference to that function. I can make curl request just fine but this multi stuff is killing me. Any help?
It was a self made function from the tutorial you are following.. Every comment explains what it does in the tutorial you are on.. ^_^
// 15. adds a url to the multi handle
function add_url_to_multi_handle($mh, $url_list) {
static $index = 0;
// if we have another url to get
if ($url_list[$index]) {
// new curl handle
$ch = curl_init();
// set the url
curl_setopt($ch, CURLOPT_URL, $url_list[$index]);
// to prevent the response from being outputted
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// follow redirections
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// do not need the body. this saves bandwidth and time
curl_setopt($ch, CURLOPT_NOBODY, 1);
// add it to the multi handle
curl_multi_add_handle($mh, $ch);
// increment so next url is used next time
$index++;
return true;
} else {
// we are done adding new URLs
return false;
}
}