0
我编写了一个php脚本,它可以帮助限制下载文件的速度和连接。我用fopen()
和fseek()
是这样的:当我们使用fopen()命令时,php加载整个文件
$f = fopen($file, 'rb');
if($f){
fseek($f,$start);//$start extracted from $_SERVER['HTTP_RANGE']
while(!feof($f)){
echo fread($f,$speed);//$speed is bytes per second
flush();
ob_flush();
sleep(1);
}
fclose($f);
}
下载过程可能需要几个小时才能完成,是整个文件在内存中,直到下载结束?以及如何优化这个?