Re: handling large files w/readfile

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux