PHP memory limitation

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi All,

This one surprised me a bit.   I wrote screen scraper in perl that
loads a 20mb file into an array etc.   I wanted to do the same
thing with a PHP program - you know - benchmarking etc....
I got this:

[jmccaughan@localhost project5]$ ./parse.php

PHP Fatal error:  Allowed memory size of 8388608 bytes exhausted
(tried to allocate 20703677 bytes) in
parse.php on line 7
[jmccaughan@localhost project5]$ ll download_src_1
-rw-rw-r-- 1 jmccaughan jmccaughan 20703676 Apr 21 10:13
[jmccaughan@localhost project5]$ cat parse.php
$infile = "download_src_1";
$filearray = file("$infile");

Is there a work-around for this?   Seem like an
odd limitation...

Thanks, --JM

Re: PHP memory limitation

Quoted text here. Click to load it

It's a 7 stage process:

1) go to
2) In the search box put "Allowed memory size of 8388608 bytes
3) Click the button that says "I'm Feeling Lucky"
4) Read the page (which just happens to be called "Solve PHP Fatal
error: Allowed memory size of 8388608 bytes exhausted")
5) Implement one of the suggestions
6) Think to yourself "Why didin't I just put the error message into
Google and press "I'm Feeling Lucky" in the first place?"
7) Resolve to do just this the next time I get an error message!

Re: PHP memory limitation

Quoted text here. Click to load it

Much classier than the lmgtfy link.  Bravo!

Re: PHP memory limitation

El 23/04/2010 18:19, joemac escribiˇ/wrote:
Quoted text here. Click to load it

It's not odd at all: if your script has no limits, some poorly written
code can take down the whole server. Whatever, the exact limits are 100%
configurable at all levels (whole server, script, instance...), e.g.:


ini_set('max_execution_time', 20*60); // 20 minutes (in seconds)
ini_set('memory_limit', '64M');


-- - ┴lvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programaciˇn web:
-- Mi web de humor satinado:

Site Timeline