下载文件sftp与curl耗尽内存

时间:2015-06-02 15:18:27

标签: php curl sftp

如何避免此错误

Fatal error: Allowed memory size of 209715200 bytes exhausted

文件非常大(超过5GB)

$host = 'domain.com';
$pass = 'xxx';

$remote = "sftp://root:$pass@$host/var/www/test.txt";
$local = 'C:\wamp\www\test.txt';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $remote);
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($curl, CURLOPT_USERPWD, "root:$pass");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
file_put_contents($local, curl_exec($curl));
curl_close($curl);

1 个答案:

答案 0 :(得分:0)

查看CURLOPT_FILE option。它会将数据直接写入给定文件。