Solve PHP Fatal Error: Allowed memory size of 8388608 bytes exhausted (tried…
Posted by Rex in PHP programming
This error message can spring up in a previously functional PHP script when the memory requirements exceed the default 8 MB limit. However, do not fret because this is an easy problem to overcome.
To change the memory limit for one specific script, include 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 does not work, keep increasing the memory limit until your script fits or your server squeals for mercy.
You can also make this a permanent change for all PHP scripts running on the server by adding a line such as 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 large data file.
The Conversation
Follow the reactions below and share your own thoughts.




October 02, 2008 at 3:40 pm, Jorge said:
Thanks for this article. It really helped a lot.
October 07, 2008 at 11:18 am, Mattia said:
tnks, u’ re great! First pos in google!
October 29, 2008 at 3:41 pm, Camilo said:
Thanks a lot!!
That function saved my day, great article.
October 30, 2008 at 9:41 pm, Movie download said:
Thanks a lot! I forgot about it
))
It’s realy usefull when use multythreads of CURL
November 10, 2008 at 11:32 pm, NICK said:
i love YOU!
November 14, 2008 at 1:09 am, Corin said:
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.
November 17, 2008 at 11:28 am, Roy Sontoloyo said:
Thanks bro…
Its realy help me…
November 20, 2008 at 12:36 pm, abedelhadi said:
thanks a lot
November 23, 2008 at 8:07 pm, Laure said:
Thanks a lot!!
That function saved my day, great article.
November 28, 2008 at 10:43 am, Adam said:
Very, very thankssssssssssss!!!!!
December 05, 2008 at 11:09 am, silverblaze said:
you can also edit the .htaccess file and add the following line..
php_value memory_limit 16M
December 05, 2008 at 7:47 pm, Diego said:
Thanks a lot for the article. Helps me out with the instalation of PhocaGallery in joomla.
December 10, 2008 at 9:23 pm, neo74 said:
Thank for this great article!!!
December 30, 2008 at 3:39 pm, ajmal said:
Alas i have issue but if i increase memory limit it shows out of memory…….
January 07, 2009 at 1:56 am, happy dude said:
brill ++++
January 12, 2009 at 6:48 pm, Joao Brito said:
Tks a lot!
January 21, 2009 at 12:56 pm, samatair said:
thanks so much for the post it helped me to sort out my image processing program..
January 31, 2009 at 7:37 am, manoj said:
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.
February 04, 2009 at 4:03 am, Manach Chuong said:
wow, thanks for your post. It’s very useful.
February 05, 2009 at 11:53 am, nitin said:
thanks yaar, its working
!!!!
February 17, 2009 at 3:44 pm, N3RVE said:
Thanks for this, very useful
February 27, 2009 at 5:41 pm, martin said:
thanks.
February 27, 2009 at 6:28 pm, WPStart said:
Saved my day
Thanks a lot
March 01, 2009 at 6:37 pm, Sebastian said:
Gracias, de verda me ayudo en mi trabajo
(Thanks a lot, it did really help me)
September 06, 2009 at 11:46 pm, Anonymous said:
Hola, soy nuevo en cuanto al tema, me podrias decir que pasos seguir para resolver este problema? te lo voy a agradecer mucho Ciao
March 12, 2009 at 12:50 pm, dewan said:
Thanks
April 11, 2009 at 10:30 pm, jordi said:
fantastic!!
April 25, 2009 at 9:34 am, saritha said:
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.
May 02, 2009 at 5:58 pm, African Safari Man said:
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…
May 07, 2009 at 6:02 pm, Joe said:
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.
May 11, 2009 at 4:06 pm, Mike said:
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…
June 07, 2010 at 4:18 am, BigMarv said:
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.
May 17, 2009 at 9:35 am, Jilani Jidni said:
cool article
May 26, 2009 at 11:27 pm, David said:
Thanks
May 30, 2009 at 7:06 pm, Tom said:
ini_set(“max_execution_time”,”600″);
ini_set(“memory_limit”,”128M”);
June 07, 2009 at 8:15 pm, Marcos said:
Excelent. Simple and direct. Thank you !
June 11, 2009 at 9:58 am, Xtube said:
Finally i solved my problem, thanks a lot
August 02, 2009 at 6:26 pm, HH said:
Thanks solved the problem. You Da Man!!
August 10, 2009 at 8:24 pm, Anonymous said:
it worked , thank you
August 11, 2009 at 4:11 pm, Maya75 said:
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
August 21, 2009 at 9:02 pm, Tiago Sousa said:
Thanks!
September 03, 2009 at 10:02 am, Anonymous said:
Thanks for me help.And Solve my problem.
Hi everybody
pls tell me something in php function.
Regards’
saleeem
September 06, 2009 at 5:25 pm, Erik Søndergaard Poulsen said:
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).
June 28, 2012 at 3:35 pm, DJDJ said:
> Thanks! This one was even easier and worked awesome!
September 06, 2009 at 11:42 pm, Anonymous said:
Hi, how can I find This files in order to modify them?, Thanks
September 23, 2009 at 5:32 pm, Swzmaster said:
thanks for your tips
October 19, 2009 at 11:51 am, Frank S. said:
Thank you ^^ !!!
I got aproblem same same with you thank you
October 26, 2009 at 11:19 am, Álvaro Garrido said:
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.
November 04, 2009 at 10:25 am, Siimi said:
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
November 26, 2009 at 12:36 am, Name said:
Hi
Thanks a lot for this.
It helped me to solve within a minute.
December 13, 2009 at 6:29 am, Anonymous said:
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?
September 08, 2010 at 11:20 am, Abc said:
gadhe kuch lika bhi hai
December 30, 2009 at 1:30 am, Mike said:
my default memory was set to 128M. i increased it up to 512M and no results. any suggestions?
January 21, 2010 at 8:12 pm, quan said:
This article help solved my issues/
Thxs a lot.
February 12, 2010 at 9:52 am, Anonymous said:
PHP Fatal error: Undefined class name ‘mail’ in C:Domainsreliantit.inwwwrootMail.php
February 16, 2010 at 8:09 am, John Edward said:
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.
February 25, 2010 at 3:44 pm, Eric Roth said:
Ah, you’ve reduced my stress level by a considerable amount!
Thank you!
March 03, 2010 at 10:49 am, Jamika Howell said:
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
March 30, 2010 at 4:26 pm, Anonymous said:
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.
April 16, 2010 at 5:08 pm, Salman said:
Thanks man… its helped me very much…
April 26, 2010 at 2:23 am, Anonymous said:
Great !
My problem is just SOLVED !
Thanks alot
April 26, 2010 at 5:14 pm, Anonymous said:
gracias por la solucion .
May 10, 2010 at 10:01 pm, Jan said:
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!
May 17, 2010 at 11:22 pm, Noberto Aquino said:
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]) }
June 03, 2010 at 7:47 pm, CyberTech said:
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.
June 10, 2010 at 4:40 am, Muchad said:
thans, very help..
June 24, 2010 at 3:12 am, Sembarang said:
tks bro really help
July 06, 2010 at 5:14 pm, Joe said:
thanks i love you
July 20, 2010 at 1:56 pm, Marlon said:
Very accurate!
August 17, 2010 at 11:13 pm, Spamabsent said:
champion!
BTW this helps when installing JCE into Joomla, just add the line into the buffer page
Thanks
Andrew
August 22, 2010 at 6:44 pm, Info said:
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
September 13, 2010 at 12:29 pm, Apnovpa said:
i like that too……..
October 01, 2010 at 1:39 pm, Rick Chew said:
nice …thank you
October 08, 2010 at 5:57 am, Ashwini Kamble said:
really good sugession
October 15, 2010 at 1:27 pm, Wendelin said:
Let me thank you for your help, dear!
It has helped me too like many others obviously…
October 31, 2010 at 8:03 pm, Canvas said:
So where do you put this memory limit ?
Thanks for the solution though
December 03, 2010 at 4:06 pm, Farhad Lavaei said:
Thank you very much, very very very useful.
December 05, 2010 at 3:50 am, Sandeep Bly said:
thanks a lot
January 17, 2011 at 1:34 pm, Cka1 said:
Very Useful, Thanks
February 23, 2011 at 7:03 pm, Gaspar said:
Thanks!!!!!!! Very Thanks!!!!!!!!!!!1
March 03, 2011 at 8:39 am, Mikekzdo said:
WOW…. the Best…. Great article…
March 10, 2011 at 7:08 am, Pathak sachchidanand said:
thanxs for this article
April 07, 2011 at 9:58 pm, Hostingalerts said:
Some servers can sometimes not accept the above codes,
In the PHP.ini file you can use the following
php_value memory_limit = 100
April 07, 2011 at 9:59 pm, Hostingalerts said:
FORGOT THE “M”
php_value memory_limit = 100M
April 25, 2011 at 8:07 am, Slawomir Piwowarczyk said:
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
April 28, 2011 at 1:31 pm, Lsiri said:
I needed this! Thanks man!
May 11, 2011 at 11:01 am, Farid Rahimi_2008 said:
tnx from the useful topic
June 02, 2011 at 10:53 am, cheap seo services said:
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
June 21, 2011 at 2:16 pm, Anonymous said:
Glad we could help!
July 11, 2011 at 3:21 pm, vijay said:
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.
August 17, 2011 at 11:40 pm, andresn said:
fwiw, check for infinite loops.
August 24, 2011 at 1:20 am, ajay said:
Please tell me where this code has to be added in which file
September 14, 2011 at 7:00 pm, Barbara said:
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!
September 15, 2011 at 11:21 am, rajesh singh said:
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
October 10, 2011 at 1:19 am, Akash said:
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?
October 26, 2011 at 12:20 am, Dila said:
wow, thanks so much!
November 19, 2011 at 11:18 am, webhost said:
Does this catch anything besides E_ERROR?
December 21, 2011 at 6:19 am, dani sukma said:
thank you, it solved my problem
January 03, 2012 at 6:02 am, vinoth said:
i used kohana.. i have same memory exceed error… pls any one help me
January 20, 2012 at 1:08 am, winner said:
for me it’s not solved. my memory is 32M
January 30, 2012 at 11:30 am, jeff said:
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 !
May 01, 2012 at 9:37 am, pankaj said:
today i am facing this problem.
now error is solved.
Thank you for great help.
May 24, 2012 at 10:54 am, Balazs said:
1024M not enought for my project.
(
June 08, 2012 at 2:05 pm, minservr said:
thanks for this article, i have the same probleme and when i change memory_limit in PHP.INI it s resolved
thanks a lot
June 10, 2012 at 6:08 am, sass said:
Thanks a lot for Great Article !
It’s solved my problem !!
I has increased memory limit till 86M.
ini_set(“memory_limit”,”86M”);
It’s really works for me !!
My CMS – joomla 1.0.15
Thank You SO MUCH !!
I has saved a lot of my time !
June 21, 2012 at 3:30 pm, ORANGE said:
I DONT HAVE WORDS TO SAY THANK YOU
July 07, 2012 at 12:54 pm, Shafeeq said:
Can anyone tell, how this happening
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 268692 bytes) in
I am new in PHP
This error occurred when tried to call same function again
August 02, 2012 at 7:21 am, Toko Online said:
Great, this article give me solution for my problem ..
thanks a lot
August 21, 2012 at 2:01 pm, Daniyal said:
Hello, It did solved the issue but dont you think its just postponing a bigger problem? WordPress is supposed to work fine under 32MB PHP limit and if it requesting more, there should be something wrong, no?
September 04, 2012 at 7:11 am, Rogelio Serrano said:
thanks dude you save my day.
September 19, 2012 at 12:58 pm, Geekyard said:
Thanks a lot I got rid off memory limit issue after trying out these steps
October 09, 2012 at 11:09 am, thanks said:
Thanks a lot it worked
October 13, 2012 at 8:47 am, HP L said:
Thanks ,
it works
Best Regards
Dimi
October 15, 2012 at 9:22 am, ikram said:
Thanx you save brain
October 30, 2012 at 12:25 am, trần công nghiệp said:
thanks ! solve my problem
November 20, 2012 at 8:06 pm, Scott Webb said:
If this is happening on a shared hosting program…call the hosting company and they will increase the limit on the spot and the problem will be resolved without you having to touch any of your code.
December 06, 2012 at 6:59 am, waqar said:
ini_set(“max_execution_time”,”1000″);
ini_set(“memory_limit”,”1024M”);
December 28, 2012 at 7:40 am, milton said:
Thanks. This worked for me!!!
March 13, 2013 at 5:42 am, cospring said:
that’s awesome!!! thanks a lot !!!
March 31, 2013 at 12:49 am, Ola said:
THANKS FOR YOUR POST!!!
April 10, 2013 at 10:39 pm, victor said:
obnrigado mano, realmente foi útil para mim isto!
October 06, 2009 at 3:32 am, common sense said:
@dsmflash : wtf noob? giving bad advice?
October 06, 2009 at 5:29 am, Anonymous said:
@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.