readfile_chunked() - do not timeout on slow (dial up) clients, and flush buffers explicitly to avoid hogging memory when ob is on

This commit is contained in:
martinlanghoff
2006-01-16 04:01:14 +00:00
parent 5703ba58e6
commit 17729fc82e
+12 -1
View File
@@ -367,10 +367,21 @@ function readfile_chunked($filename,$retbytes=true) {
if ($handle === false) {
return false;
}
// don't timeout on slow clients
@set_time_limit(0);
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
// write to the client and flush buffers
// to avoid hogging memory
echo $buffer;
flush();
if (ob_get_level() > 0) {
ob_flush();
}
if ($retbytes) {
$cnt += strlen($buffer);}
}