2012-02-22 22 views
0

我使用下面的代碼來獲取XML數據格式icecat.biz:捲曲服務器的數據傳輸超時

set_time_limit (0); 
$login = "Arpan"; 
$password = "arpan"; 
//$url="http://data.icecat.biz/export/freexml.int/EN/files.index.xml"; 
$url= "http://data.icecat.biz/export/level4/EN"; 
//$url="http://data.icecat.biz/export/freexml.int/DE/10.xml"; 

$user_agent = 'Mozilla/5.0 (Windows; U; 
Windows NT 5.1; ru; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9'; 
     $header = array(
     "Accept: text/xml,application/xml,application/xhtml+xml, 
text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", 
     "Accept-Language: ru-ru,ru;q=0.7,en-us;q=0.5,en;q=0.3", 
     "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7", 
     "Keep-Alive: 300"); 
$local_path = "myxml.xml"; 
$file_handle = fopen($local_path, "w"); 

ob_start(); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_FILE, $file_handle); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
//curl_setopt ($ch , CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_USERPWD, $login . ":" . $password); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0); // times out after 4s 
//curl_setopt($c, CURLOPT_TIMEOUT, 2); 
//curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
//$head = curl_exec($ch); 

$result = curl_exec ($ch); 

if(curl_errno($ch)) 
{ 
    echo 'Curl error: ' . curl_error($ch); 
} 

curl_close($ch); 
ob_end_clean(); 
fclose ($file_handle); 



$xmlStr = file_get_contents($local_path); 
$xmlObj = simplexml_load_string($xmlStr); 



print "<pre>"; 
//print_r($xmlObj->Product->ProductRelated->attributes()->ID); 
print_r($xmlObj); 
exit;  

頁面正在爲一個無限長的時間執行,但XML沒有被後10更新20秒輸出xml也沒有完成。我想在一段時間之後服務器沒有響應或者數據沒有被傳送。

以下是錯誤消息:

**** The server xml (icecat) size is big 

這是什麼問題,如何解決?

+0

是否有可能你的內存不足?你有什麼錯誤嗎? – gintas 2012-02-22 15:16:56

回答

0

聽起來像你沒有給予足夠的時間讓請求正常下載。

取消註釋您的// curl_setopt($ c,CURLOPT_TIMEOUT,2);

並將超時設置爲600進行測試。

除此之外,您的請求看起來不錯,您可以隨時檢查以查看服務器是否緩存響應,最近發生的最後一件事是如果我的某些用戶有反向代理來緩存其正常操作。哪些被截斷的響應被緩存,並且他們都回來了24小時,儘管這可能與您無關。

+0

@gintas這是一個很好的觀點。內存限制可能是一種真正的可能性,我們可能還需要至少查看一些響應來查找和記錄文件輸出。雖然如果響應只是保持攪動,它可能不會與內存有關,因爲php會錯誤地指出內存已經耗盡 – 2012-02-22 15:59:19

+0

嗨Will Will,感謝您的迴應。我已經使用了 curl_setopt($ c,CURLOPT_TIMEOUT,0); 我認爲這意味着「無限的捲曲執行時間」。 實際上我需要無限的時間執行。由於服務器xml大小太大。 問題仍然存在...... 感謝 – Arpan 2012-02-23 05:50:19

+0

「@gintas這是一個很好的觀點。內存限制可能是一種真正的可能性,我們可能還需要至少看到一些響應來查找和記錄文件輸出。雖然如果響應只是保持攪動它可能不會涉及到內存,因爲PHP會錯誤地指出內存已用盡「 評論: 沒有沒有內存相關的錯誤或捲曲相關的錯誤我在執行時 – Arpan 2012-02-23 05:55:52