Re: handling large files w/readfile

From: Date: Fri, 31 Dec 2004 23:17:51 +0000
Subject: Re: handling large files w/readfile
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-205442@lists.php.net to get a copy of this message
Sebastian wrote: > i'm working on a app which output files with readfile() and some headers.. > i read a comment in the manual that says if your outputting a file php > will > use the same amount of memory as the size of the file. so, if the file is > 100MB php will use 100MB of memory.. is this true? > > if it is, how can i work around this? I don't know if it's STILL true (or ever was) that readfile() would suck the whole file into RAM before spitting it out... Seems real unlikely, but... At any rate, you can simply do: $file = 'whatever.mb'; $fp = @fopen($file, 'r') or trigger_error("Could not read $file", E_USER_ERROR); while (!feof($fp)){ echo fread($fp, 4096); //4K chunks } http://php.net/fopen http://php.net/fread http://php.net/feof -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#205442) next »