note 101154 added to function.readfile

From: Date: Tue, 30 Nov 2010 09:49:40 +0000
Subject: note 101154 added to function.readfile
Groups: php.notes 
Request: Send a blank email to php-notes+get-174466@lists.php.net to get a copy of this message
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. ---- Server IP: 61.195.146.164 Probable Submitter: 202.213.203.125 ---- Manual Page -- http://www.php.net/manual/en/function.readfile.php Edit -- https://master.php.net/note/edit/101154 Del: integrated -- https://master.php.net/note/delete/101154/integrated Del: useless -- https://master.php.net/note/delete/101154/useless Del: bad code -- https://master.php.net/note/delete/101154/bad+code Del: spam -- https://master.php.net/note/delete/101154/spam Del: non-english -- https://master.php.net/note/delete/101154/non-english Del: in docs -- https://master.php.net/note/delete/101154/in+docs Del: other reasons-- https://master.php.net/note/delete/101154 Reject -- https://master.php.net/note/reject/101154 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174466) next »