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

Contributor Icon Contributed by Rex  
Tag Icon Tagged: PHP programming  

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.

 

102 Comments -


  1. Jorge said on October 2, 2008

    Thanks for this article. It really helped a lot.

  2. Mattia said on October 7, 2008

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

  3. Camilo said on October 29, 2008

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

  4. Movie download said on October 30, 2008

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

  5. NICK said on November 10, 2008

    i love YOU!

  6. 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.

  7. Roy Sontoloyo said on November 17, 2008

    Thanks bro…
    Its realy help me… ;)

  8. abedelhadi said on November 20, 2008

    thanks a lot

  9. Laure said on November 23, 2008

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

  10. Adam said on November 28, 2008

    Very, very thankssssssssssss!!!!!

  11. silverblaze said on December 5, 2008

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

    php_value memory_limit 16M

    :)

  12. Diego said on December 5, 2008

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

  13. neo74 said on December 10, 2008

    Thank for this great article!!!

  14. ajmal said on December 30, 2008

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

  15. happy dude said on January 7, 2009

    brill ++++

  16. Joao Brito said on January 12, 2009

    Tks a lot!

  17. samatair said on January 21, 2009

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

  18. 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.

  19. Manach Chuong said on February 4, 2009

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

  20. nitin said on February 5, 2009

    thanks yaar, its working ;) !!!!

  21. N3RVE said on February 17, 2009

    Thanks for this, very useful ;)

  22. martin said on February 27, 2009

    thanks.

  23. WPStart said on February 27, 2009

    Saved my day :) Thanks a lot :)

  24. Sebastian said on March 1, 2009

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

  25. dewan said on March 12, 2009

    Thanks

  26. jordi said on April 11, 2009

    fantastic!!

  27. 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.

  28. 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…

  29. 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.

  30. 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…

  31. Jilani Jidni said on May 17, 2009

    cool article

  32. David said on May 26, 2009

    Thanks

  33. Tom said on May 30, 2009

    ini_set(“max_execution_time”,”600″);
    ini_set(“memory_limit”,”128M”);

  34. Marcos said on June 7, 2009

    Excelent. Simple and direct. Thank you !

  35. Xtube said on June 11, 2009

    Finally i solved my problem, thanks a lot

  36. HH said on August 2, 2009

    Thanks solved the problem. You Da Man!!

  37. Anonymous said on August 10, 2009

    it worked , thank you

  38. 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

  39. Tiago Sousa said on August 21, 2009

    Thanks!

  40. 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

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

  42. Anonymous said on September 6, 2009

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

  43. 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

  44. Swzmaster said on September 23, 2009

    thanks for your tips

  45. common sense said on October 6, 2009

    @dsmflash : wtf noob? giving bad advice?

  46. 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.

  47. Frank S. said on October 19, 2009

    Thank you ^^ !!!

    I got aproblem same same with you thank you

  48. Á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.

  49. 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

  50. Name said on November 26, 2009

    Hi

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

  51. 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?

  52. Mike said on December 30, 2009

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

  53. quan said on January 21, 2010

    This article help solved my issues/
    Thxs a lot.

  54. Anonymous said on February 12, 2010

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

  55. 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.

  56. Eric Roth said on February 25, 2010

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

    Thank you!

  57. 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

  58. 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.

  59. Salman said on April 16, 2010

    Thanks man… its helped me very much…

  60. Anonymous said on April 26, 2010

    Great !
    My problem is just SOLVED !
    Thanks alot

  61. Anonymous said on April 26, 2010

    gracias por la solucion .

  62. 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!

  63. 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]) }

  64. 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.

  65. 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.

  66. Muchad said on June 10, 2010

    thans, very help..

  67. Sembarang said on June 24, 2010

    tks bro really help

  68. Joe said on July 6, 2010

    thanks i love you

  69. Marlon said on July 20, 2010

    Very accurate!

  70. 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

  71. 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

  72. Abc said on September 8, 2010

    gadhe kuch lika bhi hai

  73. Apnovpa said on September 13, 2010

    i like that too……..

  74. Rick Chew said on October 1, 2010

    nice …thank you

  75. Ashwini Kamble said on October 8, 2010

    really good sugession

  76. Wendelin said on October 15, 2010

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

  77. Canvas said on October 31, 2010

    So where do you put this memory limit ?

    Thanks for the solution though

  78. Farhad Lavaei said on December 3, 2010

    Thank you very much, very very very useful.

  79. Sandeep Bly said on December 5, 2010

    thanks a lot

  80. Cka1 said on January 17, 2011

    Very Useful, Thanks

  81. Gaspar said on February 23, 2011

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

  82. Mikekzdo said on March 3, 2011

    WOW…. the Best…. Great article…

  83. Pathak sachchidanand said on March 10, 2011

    thanxs for this article

  84. 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

  85. Hostingalerts said on April 7, 2011

    FORGOT THE “M”

    php_value memory_limit = 100M

  86. 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

  87. Lsiri said on April 28, 2011

    I needed this! Thanks man!

  88. Farid Rahimi_2008 said on May 11, 2011

    tnx from the useful topic

  89. 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

  90. Anonymous said on June 21, 2011

    Glad we could help!

  91. 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.

  92. andresn said on August 17, 2011

    fwiw, check for infinite loops.

  93. ajay said on August 24, 2011

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

  94. 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!

  95. 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

  96. 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?

  97. Dila said on October 26, 2011

    wow, thanks so much!

  98. webhost said on November 19, 2011

    Does this catch anything besides E_ERROR?

  99. dani sukma said on December 21, 2011

    thank you, it solved my problem

  100. vinoth said on January 3, 2012

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

  101. winner said on January 20, 2012

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

  102. 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 !

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -