RE: [PHP] readfile() problem



Hi,

It did help, but not perfectly. Sometimes I have to refresh a few times
before it will be pushed.

Best regards,
Peter

-----Original Message-----
From: Richard Lynch [mailto:ceo@xxxxxxxxx]
Sent: Friday, October 13, 2006 12:52 AM
To: Peter Lauri
Cc: php-general@xxxxxxxxxxxxx
Subject: 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
    ... readfile() will slurp the whole file into RAM, and then spit it out to ... 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, ...
    (php.general)
  • Re: Case sensitivity in programming languages.
    ... Is any language issued with a set of function names in different ... You get a warning if you reference an undeclared variable in PHP if your ... In something like PHP we could generate a convention ... The ability to have 3 different functions called readfile(), ...
    (comp.lang.php)
  • Re: Case sensitivity in programming languages.
    ... which had different functions called readfile(), ... Which excludes PHP, and this *is* a PHP newsgroup in case you hadn't noticed. ... Nope, PHP has the concept of different scopes, also. ... $foo - variable ...
    (comp.lang.php)
  • Re: Case sensitivity in programming languages.
    ... which had different functions called readfile(), ... Which excludes PHP, and this *is* a PHP newsgroup in case you hadn't ... Nope, PHP has the concept of different scopes, also. ... $foo - variable ...
    (comp.lang.php)
  • Re: Case sensitivity in programming languages.
    ... which had different functions called readfile(), ... Which excludes PHP, and this *is* a PHP newsgroup in case you hadn't noticed. ... Nope, PHP has the concept of different scopes, also. ...
    (comp.lang.php)