CURL服务器数据传输超时


CURL server data transfer timeout

我正在使用以下代码获取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

问题出在哪里?我该如何解决?

听起来您没有给请求足够的时间来正确下载。

取消注释您的//curl_setopt($c,CURLOPT_TIMEOUT,2);

并将超时设置为600进行测试。

除此之外,你的请求看起来很好,你可以随时检查服务器是否正在缓存响应,我最近看到的最后一件事是,我的一些用户是否有反向代理来缓存他们的正常操作。一些被截断的响应被缓存,这就是它们在24小时内返回的全部内容,尽管这可能与您无关。