CURL服务器数据传输超时

时间:2012-02-22 15:06:34

标签: php xml curl

我使用以下代码从icecat.biz获取xml数据:

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

问题是什么,我该如何解决?

1 个答案:

答案 0 :(得分:0)

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

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

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

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