Re: [PHP] readfile() problem



On Thu, October 12, 2006 11:43 am, Peter Lauri wrote:
I have a problem. I am using readfile() to send files to the browser.

I have three different files that I am sending. They are 3MB, 15MB and
59MB

Is there any limitations or settings of how large the files can be
when
using readfile()? If so, are they settable?

readfile() will slurp the whole file into RAM, and then spit it out to
the browser.

It's super-convenient and easy for small files.

It's not a Good Idea for large files.

fopen/fread/echo loop is your buddy.

I'll bet a dollar that your old setting had a different memory_limit
in php.ini -- or none at all, or it wasn't even compiled to allow
memory_limit -- something along those lines.

Actually, depending on the speed of the server, and its hard drives,
and the drive caches, etc, it's entirely possible that the server is
just taking TOO LONG to spit out that monster file. wget would
probably let you find out pretty quickly if it's RAM or speed that's
killing you. But it's kinda moot, really, as the solution either way
remains the same.

header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$Row[filename]");
header("Content-Transfer-Encoding: binary");

You got Content-type: right, but you know that filename thing is only
going to work on some browsers, right?
http://richardlynch.blogspot.com

Actually, I think -Type should be -type and it might be
case-sensitive, but I'd have to re-read HTTP specs to be 100% sure,
and I think all the browsers ignore case anyway, so it's kind of moot,
and I'm not THAT bored...


//readfile($filelocation);
$file = fopen($filelocation);
while (!feof($file)){
//Last I heard, 2048 optimized some PHP internal buffer...
//That's probably way out of date!
//And does not account for your bandwidth bottle-neck anyway.
//Play with the 2048 until you're happy.
echo fread($file, 2048);
}

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.



Relevant Pages

  • RE: [PHP] readfile() problem
    ... Subject: readfile() problem ... But it's kinda moot, really, as the solution either way ... and I think all the browsers ignore case anyway, so it's kind of moot, ... 2048 optimized some PHP internal buffer... ...
    (php.general)
  • Re: several browsers
    ... Have 2.52 GHz, 256 MB of Ram. ... You can have as many browsers installed as you want. ... Thou Shalt Not Install Beta Software On A Production Machine ... www.crucial.com and use the Memory Adviser Tool to see what kind of RAM you ...
    (microsoft.public.windowsxp.network_web)
  • Re: eMac value?
    ... likes ram and will use as much ram as you give it, ... So would it be better of with 9 Roger? ... browsers which effectvly have stopped 5/6 years ago. ... multimedia, ME is not so hampered though is getting there. ...
    (uk.comp.sys.mac)
  • Re: Mac mini runs very slow when on line.
    ... you have far too little RAM for your computer. ... many of the facilities to clean out caches and other maintenance ... As for your slowdowns when online, ... Try not opening your browsers, ...
    (comp.sys.mac.apps)
  • Re: Does HANDLE contain information like file pointer?
    ... located in RAM ... HANDLE to read the file content by calling "ReadFile". ... "ReadFile" operation which save the file content into a buffer. ... HANDLE into something like a pointer so that I can directly access to ...
    (microsoft.public.windowsce.platbuilder)