Solve PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried…
This error message can spring up in a previously functional PHP script when the memory requirements exceed the default 8MB limit. Don’t fret, though, because this is an easy problem to overcome.
To change the memory limit for one specific script by including a line such as this at the top of the script:
ini_set("memory_limit","12M");
The 12M sets the limit to 12 megabytes (12582912 bytes). If this doesn’t work, keep increasing the memory limit until your script fits or your server squeals for mercy.
You can also make this change permanently for all PHP scripts running on the server by adding a line like this to the server’s php.ini file:
memory_limit = 12M
Keep in mind that a huge memory limit is a poor substitute for good coding. A poorly written script may inefficiently squander memory which can cause severe problems for frequently executed scripts. However, some applications are run infrequently and require lots of memory like importing and processing a big data file.









Jorge said on October 2, 2008
Thanks for this article. It really helped a lot.
Mattia said on October 7, 2008
tnks, u’ re great! First pos in google!
Camilo said on October 29, 2008
Thanks a lot!!
That function saved my day, great article.
Movie download said on October 30, 2008
Thanks a lot! I forgot about it :)))
It’s realy usefull when use multythreads of CURL
NICK said on November 10, 2008
i love YOU!
Corin said on November 14, 2008
Thanks for the tip, Rex!
Do you know of any tool to help analyse memory usage in PHP?
I consider this a temporary workaround for my situation… I need help to reduce memory usage.
Roy Sontoloyo said on November 17, 2008
Thanks bro…
Its realy help me… ;)
abedelhadi said on November 20, 2008
thanks a lot
Laure said on November 23, 2008
Thanks a lot!!
That function saved my day, great article.
Adam said on November 28, 2008
Very, very thankssssssssssss!!!!!
silverblaze said on December 5, 2008
you can also edit the .htaccess file and add the following line..
php_value memory_limit 16M
:)
Diego said on December 5, 2008
Thanks a lot for the article. Helps me out with the instalation of PhocaGallery in joomla.
neo74 said on December 10, 2008
Thank for this great article!!!
ajmal said on December 30, 2008
Alas i have issue but if i increase memory limit it shows out of memory…….
happy dude said on January 7, 2009
brill ++++
Joao Brito said on January 12, 2009
Tks a lot!
samatair said on January 21, 2009
thanks so much for the post it helped me to sort out my image processing program..
manoj said on January 31, 2009
Actually i am new joomla user & problem is occured at the time of admin panel opened of joomla: as Allowed memory size of 8388608 bytes exhausted.
But now is solve by using this solution.
Thank you.
Manach Chuong said on February 4, 2009
wow, thanks for your post. It’s very useful.
nitin said on February 5, 2009
thanks yaar, its working ;) !!!!
N3RVE said on February 17, 2009
Thanks for this, very useful ;)
martin said on February 27, 2009
thanks.
WPStart said on February 27, 2009
Saved my day :) Thanks a lot :)
Sebastian said on March 1, 2009
Gracias, de verda me ayudo en mi trabajo
(Thanks a lot, it did really help me)
dewan said on March 12, 2009
Thanks
jordi said on April 11, 2009
fantastic!!
saritha said on April 25, 2009
nd that a huge memory limit is a poor substitute for good coding. A poorly written script may inefficiently squander memory which can cause severe problems for frequently executed scripts. However, some applications are run infrequently and require lots of memory like importing and processing a big data file.
African Safari Man said on May 2, 2009
Thanks, I couldn’t remember what the setting was called to up the limit and this did the trick. Good advice on not setting it too high, don’t want the server to run out of memory…
Joe said on May 7, 2009
You should also verify that you aren’t trying to include a file inside that file,
eg, the script name is somescript.php
and you have
include(“somescript.php”);
I’ve inadvertently done this when copying files.
Mike said on May 11, 2009
I got the weirdest one the other day;
“Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 49 bytes) in /it/doesn’t/matter/PdoDataSet.class.php on line 78″
49 is not greater than 8388608… I think there might be recursive include somewhere though. I am using the Recess! framework, so finding it is going to be a pain…
Jilani Jidni said on May 17, 2009
cool article
David said on May 26, 2009
Thanks
Tom said on May 30, 2009
ini_set(“max_execution_time”,”600″);
ini_set(“memory_limit”,”128M”);
Marcos said on June 7, 2009
Excelent. Simple and direct. Thank you !
Xtube said on June 11, 2009
Finally i solved my problem, thanks a lot
HH said on August 2, 2009
Thanks solved the problem. You Da Man!!
Anonymous said on August 10, 2009
it worked , thank you
Maya75 said on August 11, 2009
To catch PHP’s fatal errors, like “Out of memory” or “PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate … bytes) in”, see here : http://php.net/manual/en/function.set-error-handler.php#88401
Tiago Sousa said on August 21, 2009
Thanks!
Anonymous said on September 3, 2009
Thanks for me help.And Solve my problem.
Hi everybody
pls tell me something in php function.
Regards’
saleeem
Erik Søndergaard Poulsen said on September 6, 2009
You can also set the value in the .htaccess file in the root of your server by adding the following line:php_value memory_limit 64M(Create a new file named “.htaccess” if it does not exist).
Anonymous said on September 6, 2009
Hi, how can I find This files in order to modify them?, Thanks
Anonymous said on September 6, 2009
Hola, soy nuevo en cuanto al tema, me podrias decir que pasos seguir para resolver este problema? te lo voy a agradecer mucho Ciao
Swzmaster said on September 23, 2009
thanks for your tips
common sense said on October 6, 2009
@dsmflash : wtf noob? giving bad advice?
Anonymous said on October 6, 2009
@common_ass:
it’s php_value memory_limit 12M, not ini_set(“memory_limit”,”12M”).
just because its my first post here does not make me a noob. Those who accuse usually are. You SDF. Do everyone a favor and move somewhere that doesn’t have the Internet.
Frank S. said on October 19, 2009
Thank you ^^ !!!
I got aproblem same same with you thank you
Álvaro Garrido said on October 26, 2009
Keep in mind that a huge memory limit is a poor substitute for good coding. A poorly written script may inefficiently squander memory which can cause severe problems for frequently executed scripts. However, some applications are run infrequently and require lots of memory like importing and processing a big data file.
Siimi said on November 4, 2009
I have been trying to install phocagallery in my joomla site….but when i click install button then the following message is shown:-
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 998969 bytes) in C:wampwwwjoomlalibrariesjoomlafilesystemarchivezip.php on line 310
I increased the size of of memory limit in php.ini…but it still isn’t working..
Please give me another solution
Name said on November 26, 2009
Hi
Thanks a lot for this.
It helped me to solve within a minute.
Anonymous said on December 13, 2009
Hi Rex,
Can you tell the path of this configuration.php file. I find my file to be different and I did not find any ini_set parameters.
The file I am referring to, is present in my joomla installation directory. Am I using the correct cofiguration file?
Mike said on December 30, 2009
my default memory was set to 128M. i increased it up to 512M and no results. any suggestions?
quan said on January 21, 2010
This article help solved my issues/
Thxs a lot.
Anonymous said on February 12, 2010
PHP Fatal error: Undefined class name ‘mail’ in C:Domainsreliantit.inwwwrootMail.php
John Edward said on February 16, 2010
I kept increasing the memory limit on my script, it just kept going up and up to get it to run. It was a bug. Needed fixing.
Eric Roth said on February 25, 2010
Ah, you’ve reduced my stress level by a considerable amount!
Thank you!
Jamika Howell said on March 3, 2010
i keep increasing the size and it still gives me this error
Fatal error: Allowed memory size of 52428800 bytes exhausted (tried to allocate 19456 bytes) in /home/my file name.php on line 47
isnt the allowed bytes more then the allocate bytes please help
Anonymous said on March 30, 2010
And if I change for 128M, it`s such a big value??? This value can do a problem in my server memory usage?
Thanks a lot for everyone.
Salman said on April 16, 2010
Thanks man… its helped me very much…
Anonymous said on April 26, 2010
Great !
My problem is just SOLVED !
Thanks alot
Anonymous said on April 26, 2010
gracias por la solucion .
Jan said on May 10, 2010
Thanks a lot. Imagemagic did fail when I tried to upload 3+ MB files. Added your recommnded code snip: ini_set(“memory_limit”,”12M”); did adjust the size to 60MB and the Imagemagic.php script works without any problems. Glad to find such a easy solution to my problem, once again thanks!
Noberto Aquino said on May 17, 2010
In different OS (32 or 64 bits) the problem occurs.Solve in 64bits:function GetInt4d($data, $pos) { // Hacked by Andreas Rehm 2006 to ensure correct result of the $_or_24 = ord($data[$pos+3]); if ($_or_24>=128) $_ord_24 = -abs((256-$_or_24) else $_ord_24 = ($_or_24&127) return ord($data[$pos]) | (ord($data[$pos+1]) }
CyberTech said on June 3, 2010
Thank You Rex. Change in the php file itself worked. I had to increase way beyond the size of the file it was downloading using that php file.
BigMarv said on June 7, 2010
What it’s telling you is that it tried to allocate and ADDITIONAL 49 bytes. In other words, it tried to allocate one more piece of straw to go with the 8388580 bytes you already allocated in various chunks, and you broke PHP’s back.
Muchad said on June 10, 2010
thans, very help..
Sembarang said on June 24, 2010
tks bro really help
Joe said on July 6, 2010
thanks i love you
Marlon said on July 20, 2010
Very accurate!
Spamabsent said on August 17, 2010
champion!
BTW this helps when installing JCE into Joomla, just add the line into the buffer page
Thanks
Andrew
Info said on August 22, 2010
Its not proper solution for shared hosting you can even try * memory_limit = 32M to your server’s main php.ini file (recommended, if you have access) * memory_limit = 32M to a php.ini file in the Drupal root * ini_set(‘memory_limit’, ‘32M’); in your sites/default/settings.php file * php_value memory_limit 32M in your .htaccess file in the Drupal root
Abc said on September 8, 2010
gadhe kuch lika bhi hai
Apnovpa said on September 13, 2010
i like that too……..
Rick Chew said on October 1, 2010
nice …thank you
Ashwini Kamble said on October 8, 2010
really good sugession
Wendelin said on October 15, 2010
Let me thank you for your help, dear! :-)
It has helped me too like many others obviously…
Canvas said on October 31, 2010
So where do you put this memory limit ?
Thanks for the solution though
Farhad Lavaei said on December 3, 2010
Thank you very much, very very very useful.
Sandeep Bly said on December 5, 2010
thanks a lot
Cka1 said on January 17, 2011
Very Useful, Thanks
Gaspar said on February 23, 2011
Thanks!!!!!!! Very Thanks!!!!!!!!!!!1
Mikekzdo said on March 3, 2011
WOW…. the Best…. Great article…
Pathak sachchidanand said on March 10, 2011
thanxs for this article
Hostingalerts said on April 7, 2011
Some servers can sometimes not accept the above codes,
In the PHP.ini file you can use the following
php_value memory_limit = 100
Hostingalerts said on April 7, 2011
FORGOT THE “M”
php_value memory_limit = 100M
Slawomir Piwowarczyk said on April 25, 2011
REx this entry is like 6 years old, but yet serves it’s purpose. Glad I found it. It completely solved memory issues for some of my shared hosting accounts where wordpress after installing few plugins would stop responding
Lsiri said on April 28, 2011
I needed this! Thanks man!
Farid Rahimi_2008 said on May 11, 2011
tnx from the useful topic
cheap seo services said on June 2, 2011
I am getting as
Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 408 bytes)
I tried ini_set(“memory_limit”,”300M”);
but not working
Anonymous said on June 21, 2011
Glad we could help!
vijay said on July 11, 2011
When i install the Modules or link the relations of modules then it gave the fatal error.
In php.ini Memory_limit = 1024 MB , sugarcrm version : 6.2 , PHP : 5.3
But still its not solved…?
Is there any other idea to solve this…?
Yes may be its script or code related problem.
andresn said on August 17, 2011
fwiw, check for infinite loops.
ajay said on August 24, 2011
Please tell me where this code has to be added in which file
Barbara said on September 14, 2011
A word to the not-yet-wise: this is also a recipe to bring your server to its knees! A month or so ago I upped the memory limit and execution time-out to (inefficiently) deal with an unwieldy script. But, I forgot to lower it back down to a “normal” level. This week, I couldn’t figure out why my formerly stable server kept freezing up. Without limits in place, several scripts were running long and hogging resources. Limits are there for a reason. So, be careful!
rajesh singh said on September 15, 2011
my website showing fatal error :cannot access empty memory in buddypress/bpcore/bpcore notification in line 63 pls help and emil me on this email id rajeshsinghrajeshsingh100@gmail.com
Akash said on October 10, 2011
Hi,
I have a application built in Drupal6 and I am facing memory limit problem. It was 256M and then I changed it to is 512MB, still it is short by 90 bytes.
Can anyone tell me what is the max limit I can set to this variable in php.ini? If I change it to 1024, will it cause any side effects?
Dila said on October 26, 2011
wow, thanks so much!
webhost said on November 19, 2011
Does this catch anything besides E_ERROR?
dani sukma said on December 21, 2011
thank you, it solved my problem
vinoth said on January 3, 2012
i used kohana.. i have same memory exceed error… pls any one help me
winner said on January 20, 2012
for me it’s not solved. my memory is 32M
jeff said on January 30, 2012
Hi rex and everybody,
i have a problem with my prestashop ecommerce solution,
since it has been installed, i obtain white page with error like this:
Fatal error: error traversing database – perhaps it is corrupt? in /prestashop/tools/geoip/geoip.inc on line 474
A friend told me that it’s from memory too low, to write in htacess: php_value memory_limit 64M
but i had an internal error 500, no more access to anything, back-office to…
I put it off the htaccess, but i’m still at the same point…!
Some help would be very welcome !