使用Curl下载120mb的xyz.tar.gz文件


Download 120mb xyz.tar.gz file using Curl

我正在使用Curl下载150mb的xyz.tar.gz文件,但是在做Curl工作后显示无法连接到主机

然后我对另一个url做同样的事情,它的工作文件。

我不明白到底是什么问题,请告诉我。

error_reporting(E_STRICT | E_ALL);
$output_filename = "data.tar.gz";
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
$host = "http://api.innstant-servers.com:88/static.tar.gz";
$fp = fopen('./data/'.$output_filename, 'w+');
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $fp); 
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
//curl_setopt($ch, CURLOPT_URL, $host);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
print_r($result); // prints the contents of the collected file before writing..
print_r($error);
// the following lines write the contents to a file in the same directory (provided permissions etc)
//fputs($fp, $result);
fclose($fp);

由于第三方(IP)数据下载服务器防火墙不允许下载数据。首先需要在防火墙中添加白名单ip,然后数据将很容易下载。