Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CURL服务器数据传输超时_Php_Xml_Curl - Fatal编程技术网

Php CURL服务器数据传输超时

Php CURL服务器数据传输超时,php,xml,curl,Php,Xml,Curl,我使用以下代码获取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/freex

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

问题是什么?如何解决?听起来您没有给请求足够的时间来正确下载

取消注释//curl_setopt$c,CURLOPT_超时,2

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


除此之外,您的请求看起来还不错,您可以随时检查服务器是否正在缓存响应,我最近看到的最后一件事是,我的一些用户是否有反向代理以缓存其正常操作。其中一些被截断的响应被缓存了,并且在24小时内仅得到了这些响应,尽管这可能与您无关。

您是否可能内存不足?你有什么错误吗?@gintas这是一个很好的观点。内存限制可能是一种真正的可能性,我们可能还需要至少看到一些响应来查找和记录文件输出。虽然如果响应持续搅动,它可能与内存无关,因为php将出错,指出内存已耗尽。我将返回H,感谢您的响应。我使用了curl_setopt$c,CURLOPT_TIMEOUT,0;我认为这意味着执行curl的时间是无限的。实际上我需要无限时间执行。因为服务器xml大小太大。问题仍然是。。。。。。Thanks@gintas这是一个很好的观点。内存限制可能是一种真正的可能性,我们可能还需要至少看到一些响应来查找和记录文件输出。虽然如果响应持续搅动,它可能与内存无关,因为php会出错,指出内存已耗尽。注释:不,执行时没有内存相关的错误或curl相关的错误
**** The server xml (icecat) size is big