note 101154 deleted from function.readfile by danbrown

From: Date: Tue, 30 Nov 2010 15:16:13 +0000
Subject: note 101154 deleted from function.readfile by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174477@lists.php.net to get a copy of this message
Note Submitter: phpwiz at shiinaringoLESSSPAM dot se ---- Another note on the smartReadFile function from gaosipov: Beware when sending big files. They will quickly eat your memory (PHP memory, or system memory if no limit is set), because I guess somewhere PHP buffers the output. I added flushing inside the while loop, the loop that's outputting the file: <?php while (!feof($fm) && $cur < $end &&(connection_status() == 0)) { print fread($fm, min(1024 * 16, $end - $cur)); $cur += 1024 * 16; flush(); ob_flush(); } ?> With this I managed to send 200-300 MB files with a PHP memory limit set at 8 MB. Without the flushing, it would die out because of reaching the memory limit even at 128 MB. I'm not sure which of the two flushes did the trick.

« previous php.notes (#174477) next »