我尝试对eBay API进行GetItemTransactions调用。该调用基本上可以正常工作,但只返回最后一个事务(itemID)。
我认为我的cURL语法有错误,因为我使用相同的网址($ url),我将不胜感激。这是代码:
$mh = curl_multi_init();
$handles = array();
$i = 0;
$urls = array("https://api.ebay.com/ws/api.dll",
"https://api.ebay.com/ws/api.dll",
"https://api.ebay.com/ws/api.dll");
foreach ($urls as $url)
{
$handles[$url] = curl_init($url);
curl_setopt($handles[$url], CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handles[$url], CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($handles[$url], CURLOPT_HTTPHEADER, $headers);
curl_setopt($handles[$url], CURLOPT_POST, 1);
curl_setopt($handles[$url], CURLOPT_POSTFIELDS, $xml_request[$i]);
curl_setopt($handles[$url], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($mh, $handles[$url]);
$i++;
}
$ headers(它们是相同的)和$ xml_request变量被正确传输。我假设$ handles [$ url]被覆盖,因为它在每个循环中都是相同的?
答案 0 :(得分:0)
我在这里找到了类似问题/答案的答案:
Can I execute a multiple parallel cURL against the same URL?
这是新的工作代码:
$mh = curl_multi_init();
$handles = array();
$i = 0;
$url = "https://api.ebay.com/ws/api.dll";
$stationIds = array(207,303,305);
foreach ($stationIds as $stationId)
{
$handles[$stationId] = curl_init();
curl_setopt($handles[$stationId], CURLOPT_URL, $url);
curl_setopt($handles[$stationId], CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handles[$stationId], CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($handles[$stationId], CURLOPT_HTTPHEADER, $headers);
curl_setopt($handles[$stationId], CURLOPT_POST, 1);
curl_setopt($handles[$stationId], CURLOPT_POSTFIELDS, $xml_request[$i]);
curl_setopt($handles[$stationId], CURLOPT_RETURNTRANSFER, true);
curl_setopt($handles[$stationId], CURLOPT_FORBID_REUSE,1);
curl_setopt($handles[$stationId], CURLOPT_FRESH_CONNECT,1);
curl_multi_add_handle($mh, $handles[$stationId]);
$i++;
}
注意:您需要将$ stationIds的数量调整为您发送的项目数。易趣允许最多18个并行API调用。