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

Contributor Icon Contributed by Rex Date Icon November 25, 2004  
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.

Previous recipe | Next recipe |
 
  • 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.
  • 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.
  • thanks yaar, its working ;) !!!!
  • Thanks for this, very useful ;)
  • martin
    thanks.
  • Saved my day :) Thanks a lot :)
  • Gracias, de verda me ayudo en mi trabajo
    (Thanks a lot, it did really help me)
  • dewan
    Thanks
  • jordi
    fantastic!!
  • 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.
  • 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

    include("somescript.php");

    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...
  • cool article
  • David
    Thanks
  • Tom
    ini_set("max_execution_time","600");
    ini_set("memory_limit","128M");
  • Marcos
    Excelent. Simple and direct. Thank you !
  • Finally i solved my problem, thanks a lot
blog comments powered by Disqus