我可以在函数request_callback中回应我刚刚好的响应,所以我认为将响应保存到数组associative_array []中很简单,但是这只会导致单个条目,例如数组在每次输入后都会被擦除。PHP-cURL添加条目到一个不起作用的函数中的数组
我利用https://github.com/LionsAd/rolling-curl/blob/master/RollingCurl.php
<?php
# Get the all the items numbers
$url1 = "http://api.guildwars2.com/v2/commerce/listings";
$response1 = file_get_contents($url1);
$data1 = json_decode($response1, true);
#retrieve item names and link with numbers
function request_callback($response) {
$temporary_array = json_decode($response, true);
$associative_array[] = array('name' => $temporary_array['name'],'id' => $temporary_array['id']);
// array[] places the new entry at end of urls stack, faster then array_push($array, new entry);
print_r ($associative_array);
echo "\n";
}
# Multiple curl request
require("rollingcurl.php");
for ($x=0;$x<5;$x++){
$itemurl1 = "http://api.guildwars2.com/v2/items/{$data1[$x]}";
$urls[$x]= $itemurl1;
}
$rc = new RollingCurl("request_callback");
$rc->window_size = 20;
foreach ($urls as $url) {
$request = new RollingCurlRequest ($url) ;
$rc -> add ($request) ;
}
$rc->execute();
?>
'$ urls'从哪里来?你可以发布它的'var_dump'吗? – Machavity 2014-10-08 20:21:09
初学者错误尝试并行下载所有数据。尊重服务器 – 2014-10-08 20:22:15