Re: file_get_contents crash, if file is bigger than memory_limit
| From: | Jochem Maas | Date: | Sun, 24 Jun 2007 22:30:14 +0000 |
| Subject: | Re: file_get_contents crash, if file is bigger than memory_limit | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257736@lists.php.net to get a copy of this message | ||
it's difficult to read.
why?
don't top post.
oh and please post to the list.
ecc@camya.com wrote:
> 1. I dont know, if this is an feature request....
well you're the only one who might.
>
>>> given that your own comment in the example below states "while loop reading
>>> the data! (This works!)" I can't see why you *have* to use
>>> file_get_contents()
>
> Hm, strange answer, i think. Do you ever have used the file functions of php.
> Why the developers of php say, that file_get_contents is the way to read files? Maybe because
> its faster then a while contruct.
was it ever said that it's the only way?
> Or am i wrong?
>
>>> have you tried filesize() and chcked the result is less than memory_limit?
> Thats an good answer, but i think, the can also be done by php internally + throwing an
> exception :-)
ah so you were there when php core developers decided that BC would be completely broken and
all core errors would be throw as exceptions? me, I must have missed that.
php exceptions are generally a user level construct - the php core generates error not exceptions
(with the exception of a few OO based php extensions [php intended])
you might consider that you probably need to work with a tool for a little longer than
5 minutes before being in a position to determine whether a change to the tool is possible or
desirable. php is used by 100,000's of people changing the language is not something
you do 'just like that'
> Maybe i have to read the internals@lists.php.net... strange, this is like the hitchhiker. Read
> the hidden manual!
> Never head before of this internals....
> if you are a php core developer..... i´m not,
I'm not a core developer either, but that doesn't stop me following development issues
and discussions on their mailing list.
> i´m a stupid little programmer!
you said it not me, guv.
>
>>> why do you think it should throw an exception? it won't, especially not a
>>> particular class of exception that you made up o the spot.
> Never head of Pseudocode, examples?? Dont know, how to name this Exception... if you have an
> better name... "WhateverException"
>
> Ok, das musste raus... ist nicht so gemeint :-)
I'm dutch, I don't speak german - I can guess at the meaning of the above but for the sake
of
everyone else stick to english, the language used on this list, please.
>
> Gruß,
> Andreas
>
> <quote author="Jochem Maas">
> ecc wrote:
>> I really dont know, if this is the right board for this... but i think, i
>> have to write it down.
>
> if your looking to post a feature request then there is no list for that
> - the bug database would be the place to do it ... but please don't bother the
> devs with your feature request - it won't happen for reasons that are public record.
>
>> Please throw an error, if file_get_contents cant read a file because
>> memory_limit overflow!
>
> go read the archives of internals@lists.php.net for numerous reasons why that
> it not going to happen.
>
>> I´ve programmed a tool parsing checksums from large files. Because i have to
>> manage header-offsets, i have to read the files using file_get_contents.
>
> given that your own comment in the example below states "while loop reading
> the data! (This works!)" I can't see why you *have* to use file_get_contents()
>
> have you tried filesize() and chcked the result is less than memory_limit?
>
>> (This should be the fastest way for this task says the manual... right!)
>>
>> The problem is, that if the memory_limit in the php.ini is set to 64MB, and
>> the file read in by file_get_contents is bigger than 64MB, file_get_contents
>> crashes without an EXCETPION. This crash cant be catched!
>
> why do you think it should throw an exception? it won't, especially not a
> particular class of exception that you made up o the spot.
>
> php errors and exceptions are 2 different things, before going any
> further you should read up on both so that you understand the difference.
>
>> I want handle this this way:
>>
>> try{
>> $data = file_get_contents($file);
>> }
>> catch (MemoryLimitReachedException $e){
>> // try the same using a while loop reading the data! (This works!)
>> }
>>
>> Hope, there is a solution for this.
>>
>> Thank you.
>> Andreas
>> http://www.php-gtk.eu/apps/emucontrolcenter
>>
>