Solve PHP Fatal Error: Allowed memory size of 8388608 bytes exhausted (tried…

Posted November 25, 2004 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:


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.

  • Jorge

    Thanks for this article. It really helped a lot.

  • tnks, u’ re great! First pos in google!

  • Camilo

    Thanks a lot!!
    That function saved my day, great article.

  • Movie download

    Thanks a lot! I forgot about it :)))
    It’s realy usefull when use multythreads of CURL

  • NICK

    i love YOU!

  • Corin

    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

    Thanks bro…
    Its realy help me… 😉

  • abedelhadi

    thanks a lot

  • Laure

    Thanks a lot!!
    That function saved my day, great article.

  • Adam

    Very, very thankssssssssssss!!!!!

  • silverblaze

    you can also edit the .htaccess file and add the following line..

    php_value memory_limit 16M


  • Diego

    Thanks a lot for the article. Helps me out with the instalation of PhocaGallery in joomla.

  • neo74

    Thank for this great article!!!

  • ajmal

    Alas i have issue but if i increase memory limit it shows out of memory…….

  • happy dude

    brill ++++

  • Joao Brito

    Tks a lot!

  • samatair

    thanks so much for the post it helped me to sort out my image processing program..

  • manoj

    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.

  • wow, thanks for your post. It’s very useful.

  • nitin

    thanks yaar, its working 😉 !!!!

  • N3RVE

    Thanks for this, very useful 😉

  • martin


  • WPStart

    Saved my day 🙂 Thanks a lot 🙂

  • Gracias, de verda me ayudo en mi trabajo
    (Thanks a lot, it did really help me)

    • Anonymous

      Hola, soy nuevo en cuanto al tema, me podrias decir que pasos seguir para resolver este problema? te lo voy a agradecer mucho Ciao

  • dewan


  • jordi


  • saritha

    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

    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

    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


    I’ve inadvertently done this when copying files.

  • 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…

    • BigMarv

      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.

  • cool article

  • David


  • Tom


  • Marcos

    Excelent. Simple and direct. Thank you !

  • Xtube

    Finally i solved my problem, thanks a lot

  • HH

    Thanks solved the problem. You Da Man!!

  • Anonymous

    it worked , thank you

  • Maya75

    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 :

  • Thanks!

  • Anonymous

    Thanks for me help.And Solve my problem.

    Hi everybody
    pls tell me something in php function.

  • 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).

    • DJDJ

      > Thanks! This one was even easier and worked awesome!

  • Anonymous

    Hi, how can I find This files in order to modify them?, Thanks

  • Swzmaster

    thanks for your tips

  • common sense

    @dsmflash : wtf noob? giving bad advice?

    • Anonymous


      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.

  • Thank you ^^ !!!

    I got aproblem same same with you thank you

  • 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

    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


    Thanks a lot for this.
    It helped me to solve within a minute.

  • Anonymous

    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?

    • Abc

      gadhe kuch lika bhi hai

  • Mike

    my default memory was set to 128M. i increased it up to 512M and no results. any suggestions?

  • quan

    This article help solved my issues/
    Thxs a lot.

  • Anonymous

    PHP Fatal error: Undefined class name ‘mail’ in C:Domainsreliantit.inwwwrootMail.php

  • 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

    Ah, you’ve reduced my stress level by a considerable amount!

    Thank you!

  • 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

    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

    Thanks man… its helped me very much…

  • Anonymous

    Great !
    My problem is just SOLVED !
    Thanks alot

  • Anonymous

    gracias por la solucion .

  • Jan

    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

    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

    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.

  • Muchad

    thans, very help..

  • Sembarang

    tks bro really help

  • Joe

    thanks i love you

  • Marlon

    Very accurate!

  • Spamabsent

    BTW this helps when installing JCE into Joomla, just add the line into the buffer page

  • Info

    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

  • Apnovpa

    i like that too……..

  • nice …thank you

  • Ashwini Kamble

    really good sugession

  • Wendelin

    Let me thank you for your help, dear! 🙂
    It has helped me too like many others obviously…

  • So where do you put this memory limit ?

    Thanks for the solution though

  • Farhad Lavaei

    Thank you very much, very very very useful.

  • Sandeep Bly

    thanks a lot

  • Very Useful, Thanks

  • Gaspar

    Thanks!!!!!!! Very Thanks!!!!!!!!!!!1

  • Mikekzdo

    WOW…. the Best…. Great article…

  • Pathak sachchidanand

    thanxs for this article

  • Hostingalerts

    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

      FORGOT THE “M”

      php_value memory_limit = 100M

  • 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

    I needed this! Thanks man!

  • Farid Rahimi_2008

    tnx from the useful topic

  • 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

    Glad we could help!

  • vijay

    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

    fwiw, check for infinite loops.

  • ajay

    Please tell me where this code has to be added in which file

  • 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
  • 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

    wow, thanks so much!

  • webhost

    Does this catch anything besides E_ERROR?

  • dani sukma

    thank you, it solved my problem

  • vinoth

    i used kohana.. i have same memory exceed error… pls any one help me

  • winner

    for me it’s not solved. my memory is 32M

  • jeff

    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/ 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 !

  • pankaj

    today i am facing this problem.
    now error is solved.

    Thank you for great help.

  • Balazs

    1024M not enought for my project. :(( 😛

  • minservr

    thanks for this article, i have the same probleme and when i change memory_limit in PHP.INI it s resolved
    thanks a lot

  • Thanks a lot for Great Article !
    It’s solved my problem !!
    I has increased memory limit till 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 !



  • Shafeeq

    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

  • Toko Online

    Great, this article give me solution for my problem ..
    thanks a lot

  • 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?

  • Rogelio Serrano

    thanks dude you save my day.

  • Geekyard

    Thanks a lot I got rid off memory limit issue after trying out these steps 😉

  • thanks

    Thanks a lot it worked

  • HP L

    Thanks ,
    it works

    Best Regards

  • ikram

    Thanx you save brain

  • Girish

    Thanks ,
    it works for me

    Best Regards

  • thanks ! solve my problem

  • Scott Webb

    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.

  • waqar


  • milton

    Thanks. This worked for me!!!

  • cospring

    that’s awesome!!! thanks a lot !!!

  • Ola


  • victor

    obnrigado mano, realmente foi útil para mim isto!

  • toma

    thanks so much!

  • toma

    YOU’d better set more then 15M – for example 128M

  • Andy

    Thanks for sharing your solution! It was for me very helpful.

  • kiko

    great tip!!

  • rohit

    Great Men………..

  • savaliya tushae

    hello how to remove delete 404

  • Muhammad Lawal

    I tried this but I’m still getting fatal memory error.

  • ssm

    great, thank you

  • seenu

    Fatal error: Cannot redeclare xtc_DBquery()how to solve this error

    • Lacey Tech Solutions

      Without looking at the code its hard to tell you *exactly* how to fix the error however you seem to have two functions called xtc_DBquery() defined in your code.

  • piyush

    i also get smae issue, and now solved it using ini_set(“memory_limit”,”12M”);