2015-02-07 40 views
0

我嘗試對eBay API進行GetItemTransactions調用。調用基本上正常工作,但只返回最後一個事務(itemID)。eBay API - 只返回最後一個itemID的cURL_multi

我認爲在我的cURL語法中有一個錯誤,因爲我使用了相同的URL($ 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++; 

} 

$頭(它們是相同的)和$ xml_request變量正確傳輸。我認爲$ handles [$ url]會被覆蓋,因爲它在每個循環中都是一樣的?

回答

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的數量您發送的項目數量。 eBay允許最多18個並行API調用。

相關問題