Opmerking:CURLOPT_SSL_VERIFYHOST
en CURLOPT_SSL_VERIFYPEER
zijn ingesteld op 0, voor alleen api-verificatie. Deze kunnen uw server onveilig maken. Volg deze link om de juiste oplossing te krijgen.
Nu dat gezegd zijnde,
// $ids => array of ids fetched from database.
// $ids = [19019, 84444];
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$mh = curl_multi_init();
$channels = [];
foreach ($ids as $id) {
$fetchURL = 'https://eu.api.blizzard.com/data/wow/item/' . $id . '?namespace=static-eu&locale=de_DE&access_token=USDNLqVH41uJ7IST4gAnoBO4nyXBgLNIgx';
$channels[$id] = curl_init($fetchURL);
curl_setopt($channels[$id], CURLOPT_RETURNTRANSFER, 1);
// This will make your server insecure, use certificate file for the same.
curl_setopt($channels[$id], CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($channels[$id], CURLOPT_SSL_VERIFYPEER, 0);
curl_multi_add_handle($mh, $channels[$id]);
}
// execute all queries simultaneously, and continue when all are complete
$running = null;
do {
curl_multi_exec($mh, $running);
curl_multi_select($mh);
} while ($running > 0);
//close the handles
foreach ($ids as $id) {
curl_multi_remove_handle($mh, $channels[$id]);
}
curl_multi_close($mh);
$response = [];
foreach($ids as $id){
$res = curl_multi_getcontent($channels[$id]);
$response[$id] = ($res === false) ? null : json_decode($res, true);
}
echo '<pre>'; print_r($response);