curl vs普通文件下载

时间:2014-05-18 08:09:11

标签: php performance curl download

我想知道在我的服务器上转换大文件哪个更好。我有2个选项使用curl或普通的php fopen或fwrite。以下是两种实现方式。如果可能的话,你能否建议哪一个更好,有理由。

卷曲实施

$fp = fopen (dirname(__FILE__) . '/localfile.tmp', 'w+');//This is the file where we save the    information
$ch = curl_init(str_replace(" ","%20",$url));//Here is the file we are downloading, replace spaces with %20
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch); // get curl response
curl_close($ch);
fclose($fp);

正常的php实现

while(!feof($url)) {                    
 fwrite($filename, fread($file, 1024 * 8 ), 1024 * 8 );
}

0 个答案:

没有答案