Bemærk:CURLOPT_SSL_VERIFYHOST
og CURLOPT_SSL_VERIFYPEER
er sat til 0, kun for api-bekræftelse. Disse kan gøre din server usikker. Følg venligst dette link for at få en ordentlig løsning.
Når det nu er sagt,
// $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);