note 48683 deleted from function.readfile by joey

From: Date: Mon, 21 Jan 2013 10:00:47 +0000
Subject: note 48683 deleted from function.readfile by joey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193288@lists.php.net to get a copy of this message
Note Submitter: Rob Funk ---- When using readfile() with very large files, it's possible to run into problems due to the memory_limit setting; apparently readfile() pulls the whole file into memory at once. One solution is to make sure memory_limit is larger than the largest file you'll use with readfile(). A better solution is to write a chunking readfile. Here's a simple one that doesn't exactly conform to the API, but is close enough for most purposes: <?php function readfile_chunked ($filename) { $chunksize = 1*(1024*1024); // how many bytes per chunk $buffer = ''; $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, $chunksize); print $buffer; } return fclose($handle); } ?>

« previous php.notes (#193288) next »