Re: mmap in php_passthru_fd in file.c ?
| From: | Rasmus Lerdorf | Date: | Fri, 18 May 2001 05:06:36 +0000 |
| Subject: | Re: mmap in php_passthru_fd in file.c ? | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-55698@lists.php.net to get a copy of this message | ||
> > If a system has mmap() a readfile() will mmap the entire file to memory
> > and then dump that while without mmap it will read it one block at a time.
> > That's a siginificant memory difference and one that may not be expected.
> >
> > Obviously the mmap will be faster, but if as in bug #10701, someone is
> > adding headers or doing something else to really large files, things are
> > going to break. Since readfile() already has an opotional argument I
> > think the right approach is a separate function that turns the mmap off
> > and reads the file block by block. fpassthru() doesn't have an optional
> > arg, so we could toggle it there for that function.
> >
> > Comments?
> >
>
>
> Well, out of the solutions, I think the optional argument to fpassthru()
> would be the best. However, why not, as you stated in response to the
> bug report, read the file with a custom function and output it,
> therefore avoiding the mmap() as well?
Well, the one problem with that is that it can be very inefficient because
it stops reading when it hits a newline and you end up always reading
partial buffers if the file has newlines in it. Having a function that
quickly reads/dumps a file block by block would make this much more
efficient.
-Rasmus