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

130 Responses to “Solve PHP Fatal Error: Allowed memory size of 8388608 bytes exhausted (tried…”

  1. October 02, 2008 at 3:40 pm, Jorge said:

    Thanks for this article. It really helped a lot.

    Reply

  2. October 07, 2008 at 11:18 am, Mattia said:

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

    Reply

  3. October 29, 2008 at 3:41 pm, Camilo said:

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

    Reply

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

    Reply

  5. November 10, 2008 at 11:32 pm, NICK said:

    i love YOU!

    Reply

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

    Reply

  7. November 17, 2008 at 11:28 am, Roy Sontoloyo said:

    Thanks bro…
    Its realy help me… ;)

    Reply

  8. November 20, 2008 at 12:36 pm, abedelhadi said:

    thanks a lot

    Reply

  9. November 23, 2008 at 8:07 pm, Laure said:

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

    Reply

  10. November 28, 2008 at 10:43 am, Adam said:

    Very, very thankssssssssssss!!!!!

    Reply

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

    :)

    Reply

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

    Reply

  13. December 10, 2008 at 9:23 pm, neo74 said:

    Thank for this great article!!!

    Reply

  14. December 30, 2008 at 3:39 pm, ajmal said:

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

    Reply

  15. January 07, 2009 at 1:56 am, happy dude said:

    brill ++++

    Reply

  16. January 12, 2009 at 6:48 pm, Joao Brito said:

    Tks a lot!

    Reply

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

    Reply

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

    Reply

  19. February 04, 2009 at 4:03 am, Manach Chuong said:

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

    Reply

  20. February 05, 2009 at 11:53 am, nitin said:

    thanks yaar, its working ;) !!!!

    Reply

  21. February 17, 2009 at 3:44 pm, N3RVE said:

    Thanks for this, very useful ;)

    Reply

  22. February 27, 2009 at 5:41 pm, martin said:

    thanks.

    Reply

  23. February 27, 2009 at 6:28 pm, WPStart said:

    Saved my day :) Thanks a lot :)

    Reply

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

    Reply

    • 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

      Reply

  25. March 12, 2009 at 12:50 pm, dewan said:

    Thanks

    Reply

  26. April 11, 2009 at 10:30 pm, jordi said:

    fantastic!!

    Reply

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

    Reply

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

    Reply

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

    Reply

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

    Reply

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

      Reply

  31. May 17, 2009 at 9:35 am, Jilani Jidni said:

    cool article

    Reply

  32. May 26, 2009 at 11:27 pm, David said:

    Thanks

    Reply

  33. May 30, 2009 at 7:06 pm, Tom said:

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

    Reply

  34. June 07, 2009 at 8:15 pm, Marcos said:

    Excelent. Simple and direct. Thank you !

    Reply

  35. June 11, 2009 at 9:58 am, Xtube said:

    Finally i solved my problem, thanks a lot

    Reply

  36. August 02, 2009 at 6:26 pm, HH said:

    Thanks solved the problem. You Da Man!!

    Reply

  37. August 10, 2009 at 8:24 pm, Anonymous said:

    it worked , thank you

    Reply

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

    Reply

  39. August 21, 2009 at 9:02 pm, Tiago Sousa said:

    Thanks!

    Reply

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

    Reply

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

    Reply

    • June 28, 2012 at 3:35 pm, DJDJ said:

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

      Reply

  42. September 06, 2009 at 11:42 pm, Anonymous said:

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

    Reply

  43. September 23, 2009 at 5:32 pm, Swzmaster said:

    thanks for your tips

    Reply

  44. October 06, 2009 at 3:32 am, common sense said:

    @dsmflash : wtf noob? giving bad advice?

    Reply

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

      Reply

  45. October 19, 2009 at 11:51 am, Frank S. said:

    Thank you ^^ !!!

    I got aproblem same same with you thank you

    Reply

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

    Reply

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

    Reply

  48. November 26, 2009 at 12:36 am, Name said:

    Hi

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

    Reply

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

    Reply

    • September 08, 2010 at 11:20 am, Abc said:

      gadhe kuch lika bhi hai

      Reply

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

    Reply

  51. January 21, 2010 at 8:12 pm, quan said:

    This article help solved my issues/
    Thxs a lot.

    Reply

  52. February 12, 2010 at 9:52 am, Anonymous said:

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

    Reply

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

    Reply

  54. February 25, 2010 at 3:44 pm, Eric Roth said:

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

    Thank you!

    Reply

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

    Reply

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

    Reply

  57. April 16, 2010 at 5:08 pm, Salman said:

    Thanks man… its helped me very much…

    Reply

  58. April 26, 2010 at 2:23 am, Anonymous said:

    Great !
    My problem is just SOLVED !
    Thanks alot

    Reply

  59. April 26, 2010 at 5:14 pm, Anonymous said:

    gracias por la solucion .

    Reply

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

    Reply

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

    Reply

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

    Reply

  63. June 10, 2010 at 4:40 am, Muchad said:

    thans, very help..

    Reply

  64. June 24, 2010 at 3:12 am, Sembarang said:

    tks bro really help

    Reply

  65. July 06, 2010 at 5:14 pm, Joe said:

    thanks i love you

    Reply

  66. July 20, 2010 at 1:56 pm, Marlon said:

    Very accurate!

    Reply

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

    Reply

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

    Reply

  69. September 13, 2010 at 12:29 pm, Apnovpa said:

    i like that too……..

    Reply

  70. October 01, 2010 at 1:39 pm, Rick Chew said:

    nice …thank you

    Reply

  71. October 08, 2010 at 5:57 am, Ashwini Kamble said:

    really good sugession

    Reply

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

    Reply

  73. October 31, 2010 at 8:03 pm, Canvas said:

    So where do you put this memory limit ?

    Thanks for the solution though

    Reply

  74. December 03, 2010 at 4:06 pm, Farhad Lavaei said:

    Thank you very much, very very very useful.

    Reply

  75. December 05, 2010 at 3:50 am, Sandeep Bly said:

    thanks a lot

    Reply

  76. January 17, 2011 at 1:34 pm, Cka1 said:

    Very Useful, Thanks

    Reply

  77. February 23, 2011 at 7:03 pm, Gaspar said:

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

    Reply

  78. March 03, 2011 at 8:39 am, Mikekzdo said:

    WOW…. the Best…. Great article…

    Reply

  79. March 10, 2011 at 7:08 am, Pathak sachchidanand said:

    thanxs for this article

    Reply

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

    Reply

    • April 07, 2011 at 9:59 pm, Hostingalerts said:

      FORGOT THE “M”

      php_value memory_limit = 100M

      Reply

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

    Reply

  82. April 28, 2011 at 1:31 pm, Lsiri said:

    I needed this! Thanks man!

    Reply

  83. May 11, 2011 at 11:01 am, Farid Rahimi_2008 said:

    tnx from the useful topic

    Reply

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

    Reply

  85. June 21, 2011 at 2:16 pm, Anonymous said:

    Glad we could help!

    Reply

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

    Reply

  87. August 17, 2011 at 11:40 pm, andresn said:

    fwiw, check for infinite loops.

    Reply

  88. August 24, 2011 at 1:20 am, ajay said:

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

    Reply

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

    Reply

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

    Reply

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

    Reply

  92. October 26, 2011 at 12:20 am, Dila said:

    wow, thanks so much!

    Reply

  93. November 19, 2011 at 11:18 am, webhost said:

    Does this catch anything besides E_ERROR?

    Reply

  94. December 21, 2011 at 6:19 am, dani sukma said:

    thank you, it solved my problem

    Reply

  95. January 03, 2012 at 6:02 am, vinoth said:

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

    Reply

  96. January 20, 2012 at 1:08 am, winner said:

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

    Reply

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

    Reply

  98. May 01, 2012 at 9:37 am, pankaj said:

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

    Thank you for great help.

    Reply

  99. May 24, 2012 at 10:54 am, Balazs said:

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

    Reply

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

    Reply

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

    Reply

  102. June 21, 2012 at 3:30 pm, ORANGE said:

    I DONT HAVE WORDS TO SAY THANK YOU

    Reply

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

    Reply

  104. August 02, 2012 at 7:21 am, Toko Online said:

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

    Reply

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

    Reply

  106. September 04, 2012 at 7:11 am, Rogelio Serrano said:

    thanks dude you save my day.

    Reply

  107. September 19, 2012 at 12:58 pm, Geekyard said:

    Thanks a lot I got rid off memory limit issue after trying out these steps ;-)

    Reply

  108. October 09, 2012 at 11:09 am, thanks said:

    Thanks a lot it worked

    Reply

  109. October 13, 2012 at 8:47 am, HP L said:

    Thanks ,
    it works

    Best Regards
    Dimi

    Reply

  110. October 15, 2012 at 9:22 am, ikram said:

    Thanx you save brain

    Reply

  111. October 29, 2012 at 7:24 am, Girish said:

    Thanks ,
    it works for me

    Best Regards
    Girish

    Reply

  112. October 30, 2012 at 12:25 am, trần công nghiệp said:

    thanks ! solve my problem

    Reply

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

    Reply

  114. December 06, 2012 at 6:59 am, waqar said:

    ini_set(“max_execution_time”,”1000″);
    ini_set(“memory_limit”,”1024M”);

    Reply

  115. December 28, 2012 at 7:40 am, milton said:

    Thanks. This worked for me!!!

    Reply

  116. March 13, 2013 at 5:42 am, cospring said:

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

    Reply

  117. March 31, 2013 at 12:49 am, Ola said:

    THANKS FOR YOUR POST!!!

    Reply

  118. April 10, 2013 at 10:39 pm, victor said:

    obnrigado mano, realmente foi útil para mim isto!

    Reply

  119. July 16, 2013 at 8:16 am, toma said:

    thanks so much!

    Reply

  120. July 16, 2013 at 8:17 am, toma said:

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

    Reply

  121. December 27, 2013 at 6:15 am, Andy said:

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

    Reply

  122. January 23, 2014 at 6:36 pm, kiko said:

    great tip!!

    Reply

  123. March 24, 2014 at 4:45 am, rohit said:

    Great Men………..

    Reply

  124. April 09, 2014 at 8:05 am, savaliya tushae said:

    hello how to remove delete 404

    Reply

Leave a Reply