[prev in list] [next in list] [prev in thread] [next in thread]
List: php-general
Subject: RE: [PHP] file_get_contents limit
From: "Daevid Vincent" <daevid () daevid ! com>
Date: 2010-06-29 21:18:12
Message-ID: 3FB42A464A6741418F70D1AA7A89F93D () mascorp ! com
[Download RAW message or body]
> -----Original Message-----
> From: Andrew Ballard [mailto:aballard@gmail.com]
> Sent: Tuesday, June 29, 2010 1:56 PM
> To: ash@ashleysheridan.co.uk
> Cc: Jo?o C?ndido de Souza Neto; php-general@lists.php.net
> Subject: Re: [PHP] file_get_contents limit
>
> On Tue, Jun 29, 2010 at 4:39 PM, Ashley Sheridan
> <ash@ashleysheridan.co.uk> wrote:
> >
> > On Tue, 2010-06-29 at 16:37 -0400, Andrew Ballard wrote:
> >
> > > On Tue, Jun 29, 2010 at 4:21 PM, Ashley Sheridan
> > > <ash@ashleysheridan.co.uk> wrote:
> > > >
> > > > Have you looked at the memory settings in php.ini?
> > > >
> > >
> > > I doubt that is the cause, at least not by itself. 21504
> characters is
> > > only 21K of data (could be more if the characters are multi-byte
> > > encoded, but still less than 100K) , and the default
> memory limit in
> > > PHP is 128M. I'm not sure what else it could be, though,
> as I don't
> > > see any limitations on file_get_contents() discussed in
> the manual.
> >
> > Default memory limit is still 32MB on every default install
> I've seen.
> >
>
> The manual currently shows 128M, and that's what I've seen for some
> time now. Even so, a function returning less than 100K shouldn't
> exhaust 32M of memory either, unless something else is at play. If
> there is a memory limit being reached, PHP should log either an error
> or warning (I can't remember which).
Maybe try to specify the number of $maxlen bytes to read?
http://us4.php.net/file_get_contents
string file_get_contents ( string $filename [, bool $use_include_path =
false [, resource $context [, int $offset = -1 [, int $maxlen = -1
]]]] )
You could also do it the faster and "old fashioned" way:
$fh = fopen('/tmp/test.zip', 'r');
$data = fread($fh, filesize('/tmp/test.zip'));
fclose($fh);
Or if it's multibyte maybe try this:
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic