I have a mysql table "blackrock" (it has over 14.000 rows).
item_id | item_class | item_subclass | actual_price | actual_quantity
---------------------------------------------------------------------
19019 | 2 | 7 | 5727700 | 12
84444 | 2 | 1 | 5888040 | 52
....
I need the item_id of each row to connect to an extern json API file. Every item_id has his own json file. Here is an example. The 19019 is the item_id.
https://eu.api.blizzard.com/data/wow/item/19019?namespace=static-eu&locale=de_DE&access_token=USDNLqVH41uJ7IST4gAnoBO4nyXBgLNIgx
I think the best way ist to do this is with multi_curl. I don′t know how to combine the table query and the multi_curl funcion.
This is my database table query:
// Retrieve data from database
$result= $mysqli->query("
SELECT item_id
FROM blackrock
");
while($rows=mysqli_fetch_array($result)){
}
Multi Curl (I need to use a user agent, maybe there is a mistake)
$multiCurl = array();
// data to be returned
$result = array();
// multi handle
$mh = curl_multi_init();
foreach ($ids as $i => $id) {
// URL from which data will be fetched
$fetchURL = 'https://eu.api.blizzard.com/data/wow/item/' . $id . '?namespace=static-eu&locale=de_DE&access_token=USDNLqVH41uJ7IST4gAnoBO4nyXBgLNIgx';
$multiCurl[$i] = curl_init();
curl_setopt($multiCurl[$i], CURLOPT_USERAGENT, $userAgent);
curl_setopt($multiCurl[$i], CURLOPT_URL,$fetchURL);
curl_setopt($multiCurl[$i], CURLOPT_HEADER,0);
curl_setopt($multiCurl[$i], CURLOPT_RETURNTRANSFER,1);
curl_multi_add_handle($mh, $multiCurl[$i]);
}
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$index=null;
do {
curl_multi_exec($mh,$index,$userAgent);
} while($index > 0);
// get content and remove handles
foreach($multiCurl as $k => $ch) {
$result[$k] = curl_multi_getcontent($ch);
curl_multi_remove_handle($mh, $ch);
}
var_dump(json_decode($result));
// close
curl_multi_close($mh);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…