cpuphp下载
<code> <?php/* Source: http://www.apphp.com/index.php?snippet=php-download-file-with-speed-limit */ /* set here a limit of downloading rate (e.g. 10.20 Kb/s) */ // $download_rate = 10.20; $download_rate = 200; set_time_limit(0); $download_file = 'myfile.rar'; $target_file = 'PHP敏捷开发CodeIgniter框架.rar'; if(file_exists($download_file)){ /* headers */ header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Cache-control: private'); header('Content-Type: application/octet-stream'); //HTTP Content-type ( 二进制流,不知道下载文件类型) header('Content-Length: '.filesize($download_file)); header('Content-Disposition: filename='.$target_file); /* flush content */ flush(); /* open file */ $fh = @fopen($download_file, 'r'); while(!feof($fh)){ /* send only current part of the file to browser */ print fread($fh, round($download_rate * 1024)); /* flush the content to the browser */ flush(); /* sleep for 1 sec */ sleep(1); } /* close file */ @fclose($fh); }else{ die('Fatal error: the '.$download_file.' file does not exist!'); } ?></code>
怎么又生带宽,又省cpu 和内存?
1.是不sleep 控制下载速度好呢,还是sleep一下省下带宽呢?
2,每次读取2进制多少个字节合适呢,还是越大越好,还是小点分多次读取好?
本人小白,先谢过各位大侠了。。