Я использую следующую функцию для запуска мульти URLs с Скручиваниемфункция Curl сбиваться при обработке массива
function multiRequest($data, $options = array()) {
// array of curl handles
$curly = array();
// data to be returned
$result = array();
// multi handle
$mh = curl_multi_init();
// loop through $data and create curl handles
// then add them to the multi-handle
foreach ($data as $id => $d) {
$curly[$id] = curl_init();
$url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
curl_setopt($curly[$id], CURLOPT_URL, $url);
curl_setopt($curly[$id], CURLOPT_HEADER, 0);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
// post?
if (is_array($d)) {
if (!empty($d['post'])) {
curl_setopt($curly[$id], CURLOPT_POST, 1);
curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
}
}
// extra options?
if (!empty($options)) {
curl_setopt_array($curly[$id], $options);
}
curl_multi_add_handle($mh, $curly[$id]);
}
// execute the handles
$running = null;
do {
curl_multi_exec($mh, $running);
} while($running > 0);
// get content and remove handles
foreach($curly as $id => $c) {
$result[$id] = curl_multi_getcontent($c);
curl_multi_remove_handle($mh, $c);
}
// all done
curl_multi_close($mh);
return $result;
}
Тогда я массив, который используется:
Array
(
[0] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Negev+%7C+Nuclear+Waste+%28Minimal+Wear%29
[1] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Chroma+2+Case
[2] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Operation+Wildfire+Case
[3] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Operation+Breakout+Weapon+Case
[4] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=MP9+%7C+Storm+%28Field-Tested%29
[5] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Dual+Berettas+%7C+Cartel+%28Well-Worn%29
[6] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Sawed-Off+%7C+Bamboo+Shadow+%28Minimal+Wear%29
[7] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=MAC-10+%7C+Lapis+Gator+%28Field-Tested%29
[8] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Revolver+Case
[9] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=MP9+%7C+Storm+%28Field-Tested%29
[10] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=USP-S+%7C+Lead+Conduit+%28Well-Worn%29
[11] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P2000+%7C+Handgun+%28Battle-Scarred%29
[12] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=StatTrak%E2%84%A2+Nova+%7C+Ranger+%28Field-Tested%29
[13] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Shadow+Case
[14] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Galil+AR+%7C+Sage+Spray+%28Field-Tested%29
[15] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Chroma+2+Case
[16] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Desert+Eagle+%7C+Mudder+%28Field-Tested%29
[17] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Operation+Breakout+Weapon+Case
[18] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Shadow+Case
[19] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Chroma+2+Case
[20] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Revolver+Case
[21] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Galil+AR+%7C+VariCamo+%28Field-Tested%29
[22] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Chroma+2+Case
[23] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=SG+553+%7C+Pulse+%28Field-Tested%29
[24] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=MAG-7+%7C+Heaven+Guard+%28Factory+New%29
[25] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Tec-9+%7C+Sandstorm+%28Minimal+Wear%29
[26] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Nova+%7C+Ranger+%28Minimal+Wear%29
[27] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=M4A4+%7C+%E9%BE%8D%E7%8E%8B+%28Dragon+King%29+%28Minimal+Wear%29
[28] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Glock-18+%7C+Bunsen+Burner+%28Battle-Scarred%29
[29] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=%E2%98%85+Bayonet+%7C+Doppler+%28Factory+New%29
[30] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P250+%7C+Mint+Kimono+%28Field-Tested%29
[31] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P2000+%7C+Amber+Fade+%28Factory+New%29
[32] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=MP7+%7C+Urban+Hazard+%28Factory+New%29
[33] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Five-SeveN+%7C+Urban+Hazard+%28Factory+New%29
[34] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=AK-47+%7C+Cartel+%28Field-Tested%29
[35] => http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=FAMAS+%7C+Pulse+%28Factory+New%29
)
Этот массив будет меняться в длину и может быть в сотнях.
Когда я вызываю функцию и печать:
$r = multiRequest($data);
echo '<pre>';
print_r($r);
Я могу следующий вывод:
Array
(
[0] => {"success":true,"lowest_price":"$0.28","volume":"147","median_price":"$0.27"}
[1] => ��+����O��%
[2] => {"success":true,"lowest_price":"$0.35","volume":"86,853","median_price":"$0.34"}
[3] => {"success":true,"lowest_price":"$0.04","volume":"78,246","median_price":"$0.03"}
[4] => {"success":true,"lowest_price":"$0.05","volume":"716","median_price":"$0.03"}
[5] => {"success":true,"lowest_price":"$0.13","volume":"668","median_price":"$0.12"}
[6] => {"success":true,"lowest_price":"$0.16","volume":"481","median_price":"$0.16"}
[7] => {"success":true,"lowest_price":"$0.13","volume":"1,186","median_price":"$0.13"}
[8] => ��+����O��%
[9] => {"success":true,"lowest_price":"$0.05","volume":"716","median_price":"$0.03"}
[10] => ��+����O��%
[11] => ��+����O��%
[12] => {"success":true,"lowest_price":"$0.26","volume":"245","median_price":"$0.28"}
[13] => {"success":true,"lowest_price":"$0.04","volume":"50,035","median_price":"$0.04"}
[14] => {"success":true,"lowest_price":"$0.04","volume":"1,808","median_price":"$0.02"}
[15] => {"success":true,"lowest_price":"$0.15","volume":"96,991","median_price":"$0.15"}
[16] => {"success":true,"lowest_price":"$0.06","volume":"1,716","median_price":"$0.04"}
[17] => ��+����O��%
[18] => {"success":true,"lowest_price":"$0.04","volume":"50,035","median_price":"$0.04"}
[19] => ��+����O��%
[20] => ��+����O��%
[21] => {"success":true,"lowest_price":"$0.05","volume":"1,488","median_price":"$0.04"}
[22] => {"success":true,"lowest_price":"$0.15","volume":"96,991","median_price":"$0.15"}
[23] => {"success":true,"lowest_price":"$0.38","volume":"1,478","median_price":"$0.42"}
[24] => ��+����O��%
[25] => ��+����O��%
[26] => ��+����O��%
[27] => ��+����O��%
[28] => {"success":true,"lowest_price":"$0.11","volume":"714","median_price":"$0.11"}
[29] => {"success":true,"lowest_price":"$268.33","volume":"45","median_price":"$264.49"}
[30] => ��+����O��%
[31] => {"success":true,"lowest_price":"$0.93","volume":"524","median_price":"$0.95"}
[32] => ��+����O��%
[33] => ��+����O��%
[34] => ��+����O��%
[35] => ��+����O��%
)
Когда я обновить, то индексирование массива, которые тянут через данные и индексирование массива, которые не изменения. Чем это вызвано? Как это будет отличаться для массива 900+.
Я добавил curl_setopt ($ ч, CURLOPT_ENCODING, "UTF-8"); и все, что я возвращаю, это null – Matt