which is the best way to download from php large files without consuming all server\'s memory?
I could do this (bad code):
$url=\'http://server/bigfile\'
You can use curl and the option CURLOPT_FILE to save the downloaded content directly to a file.
set_time_limit(0);
$fp = fopen ('file', 'w+b');
$ch = curl_init('http://remote_url/file');
curl_setopt($ch, CURLOPT_TIMEOUT, 75);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);