Community Documentation

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes)...

Last updated July 1, 2011. Created by dman on July 29, 2006.
Edited by adTumbler, Christopher Jam..., gpk, TravisCarden. Log in to edit this page.

That indicates that Drupal needed more memory than PHP was allowed to give it.

Drupal 7

  • Memory increase to 128M:
    (This has worked every-time; and used to always work for D6 as well)

    Create a new file php.ini, and add the code...
    php_value memory_limit = "128M"
    and put that file in your Drupal 7 (or D6) root folder.
  • If you need more than 128M:

    Add the line
    ini_set('memory_limit', '512M');
    to your [Drupal 7 root]/sites/default/settings.php file.

    I have yet to need this much memory, but I did achieve
    a memory increase to 512M using this slightly more complicated
    process that involved temporarily changing the permission level
    for that file.

End Drupal 7

===================

Increase PHP's memory limit, e.g. to increase it to 32M you could try adding:

  • 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

You can also try Drupal tweaks module.

On most hosts not all of the above methods will work, and some shared hosts will not allow any modification of your capacity at all. Slightly more instructions on increasing PHP memory on your server in the installation guide.

Depending on the amount of modules you have enabled and their 'impact' on the site you may need to increase the memory_limit even more (sometimes to 32 MB or more). Image processing often takes a lot of memory, as can working with any large files. Experiment with what memory value works for your needs.

Clearly, if your error was memory size of 16777216 bytes exhausted (16M) in the first place, then you are going to have to be bumping the limit up even higher than that. Do the binary thing and double it to 32M.

You may need to restart your server before the php.ini settings take effect.

Note: Do not just set an arbitrarily high number just to avoid this potential problem - it may limit your ability to have multiple simultaneous connections run efficiently, and simultaneous connections are important on web servers.

Note: There is no way to know how many or what combination of modules will put any one account over their memory limit. Every module uses a different amount of memory. Core requires memory by itself and requirements for core alone should be understood. see: http://drupal.org/requirements

Note: Despite what Status report shows, and changes to php.ini indicate - 1and 1 limit a developer account to 30M. This is not enough to activate all the modules required for Drupal Commerce. The solution is to upgrade your account at 1and 1 - to the next level which gives 90M

Comments

1and1.com Configuration

Running 1and1 Developer Server (Not Dedicated)

Okay, did the above and it failed.
Forget about the memory limits in the php.ini and .htaccess file. Just use the above line
ini_set('memory_limit', '16M'); in settings.php

This worked for me.

Also, note that you should manually setup your db information as specified in step 19 of this page:
http://www.ehow.com/how_4858748_install-drupal-servers.html

You should have a php.ini file with the following in it uploaded to your root where the domain is pointed for your site.
register_globals = off;

.htaccess should have
"ON" capitalized for "RewriteEngine on" as well at this line at the top
AddType x-mapp-php5 .php

MEMORY LIMIT ON DREAMHOST PRIVATE SERVER PS ?

MEMORY LIMIT ON DREAMHOST PRIVATE SERVER PS ?

Hello,

I set

ini_set('memory_limit', '150M');

in your sites/default/settings.php file

because 100M was not working anymore for a very large website, do you know what is the limit on DREAMHOST servers ?

Can you think of any problem if i set the limit to 200 or more to be safe in the future ?

Thanks.

Worked For Me

wwwoliondorcom this worked for me. Perfectly straight forward post Thanks for the Help. don't know much about this sorry I can't answer your question.

I have been fighting this problem as well

Making changes in both .htaccess and settings.php finally fixed it. Thank you for the extra info on .htaccess as well WeagleDude. Its about time someone made a fix crystal clear!

Ali
Gator's Guides & www.allisonelizabeth.net

Drupal does not release memory as it should ?

Hi,

I noticed that once you have this problem, it is difficult to pinpoint and solve. As memory is mostly fixed with hosting partners, increasing it is more a workaround then solution.

How can one discover what is the cause and where the faulty code could be.

Any experience on tracking down the memory usage and optimizing it would be helpfull.

Joel Box - Mondial-IT

Running out of memory isn't a single 'bug'

You misunderstand the problem. It's not a case of any one bit of faulty code. It's a case of aggregate capacity.
If you order a meal that costs $20 and you only have $16 to pay for it. There is a problem. There is no "work-around". It's not the "fault" of the sauce or the lettuce.

You just need to get hold of $20. Or choose to do without the entree.

If you are interested in debugging, the devel.module provides a number of tools that help trace performance. You can install XDebug for memory profiling if you like. Also there has been heaps of work on Drupal performance if you want to look.
Your host also has the ability to provide you with the Apache and PHP logs that will pinpoint exactly what was happening when a memory failure occurred.

Note that even if you find the point in the code where the memory ran out, the point of failure is almost never the cause of memory issues. Memory issues mean that something in the process somewhere before the failure point needed to use more memory than you chose to provide it. And the point of failure may change radically depending on the content it is running over.
A memory blowout is a result of the amount of work done, the size of the content and the complexity of the page. It could be that rendering a complex view with 6 items takes 15Mb and rendering it with 8 items takes 17Mb and causes a memory fail when processing comment.module.
It's not the fault of the extra two items, it's not the fault of comment.module.
It's that you need an appropriate amount of capacity.

So yes, it's tricky to pinpoint. But use the tools and you can.

Of course memory is used in

Of course memory is used in many modules and processes, however runaway memory and not returned memory only by ill-behaving code. It is quite clear to the developer what size an array, a form or table is and drupal offers ampel options to savely store large data into the database. In the modules you see some using a few hundred k, while an import module takes a full 8Megs. That sort of narrows down where to optimize.

My problem is specifically with modules where code is not returning or decreasing memory (use of globals, statics and arraycopies.

Perhaps sometime I will have a go at enhancing the profiler and "swap" memory close to limit to disk...

Kind regards.

Joel Box - Mondial-IT

not necessarily PHP...

note that there can be memory bottlenecks other than PHP.

working on a WiredTree VPS account recently, it took me awhile to figure out that Apache's RLimitMEM directive was the culprit rather than PHP's memory_limit. presumably this could be fixed by altering either httpd.conf or via an .htaccess file.

there are many discussions of these problems on d.o, but it can be hard to find them. this comment in particular, was helpful for me.

Easy Fix

I just spent two days wading through the mystery quagmire that is the memory limit files for drupal. After trying to modify and change the htaacess and the setting.php file I finally got fed up and called the provider. They told me to make a text file named php.ini and drop in this snippet of code php_value memory_limit 200M . This works for a greengeeks hosted account. I hope that this can save someone valuable time.

Permissions problem

Thanks for the info. This was most helpful at eliminating the memory limit, although I'm troubleshooting a permissions error on the file that puts things into Safe Mode. Did you run into any permissions problems with access to the file or the TMP files?

(This solution had always worked for Drupal 6 as well,
back when I used to use D6.)

By default, Drupal 7 at my online webhost allocates 64M (megabytes) of memory
and so if you are experiencing this error, you need to increase that limit to
128M.

I always get this error after installing several additional modules (Contributed modules)
and the solution that always works is...

  1. Open a text file editor. (Eg. WordPad, NotePad, etc.)
  2. Add the text
    php_value memory_limit = "128M"
  3. Save the file with the file-name
    php.ini
    • It is critical that this file be saved with the name php.ini
      because in the case of your using the Microsoft windows operating system
      the file might be saved as "php.ini.txt" without your being aware of that fact.

      That is the default condition with using NotePad or WordPad with Windows XP,
      for example, because of the default setting...
      'Tools' > 'Folder settings' > tab: 'View' >
      check-box 'Hide extensions for known file types'...
      and is evidenced if you see the file listed as simply "php".

      Feel free to un-check that folder options setting check-box,
      and click the bottom button 'OK',
      and you will there-after always see the actual file extensions
      for all the files on your system.

  4. Place the file php.ini into the root folder (also known as 'root directory')
    so that it is in the directory that also containing folders
    'includes', 'misc', 'modules', 'profiles', 'scripts', etc.

The problem should be over immediately.

Additional notes:

  • You can see the amount of memory you are being allowed by going to
    'Reports' > 'Status report'; and scrolling down to "PHP memory limit".
    It should read '128M' if you have followed the above steps.
  • Increasing the php.ini code from "128M" to "256M" did not change my
    status report amount, and it still reads "128M".
  • Decreasing the php.ini code from "128M" to "64M" also did not change my
    status report amount back to "64M", and it still remains "128M";
    although I did change the php.ini code back to "128M".

If you need more than 128M, the solution is slightly more complicated.

See the comment below, "Drupal 7 memory increase to more than 128M"

Drupal 7 memory increase to more than 128M

Drupal 7: If you need more than 128M, then add the line
ini_set('memory_limit', '512M');
to your [Drupal 7 root]/sites/default/settings.php file.

I have yet to need this much memory, but I did achieve
a memory increase to 512M using this slightly more complicated
process that involved temporarily changing the permission level
for that file at my online webhost.

The following applies to an online installation,
but if your installation is "local" on your computer
just follow the instructions below and ignore the extra steps
required for the online installation.

I have not tried the Local approach, but I assume
it would work equally well.

  1. Download a copy of the file "settings.php"
    (if you do not already have a copy on your computer)
    that is located at
    [Drupal 7 root]/sites/default/settings.php
  2. Open the file with your favorite text editor
    (Eg. WordPad, NotePad, etc.).
  3. Add a line of code on a line of its own
    at the bottom of that file...
    ini_set('memory_limit', '512M');
  4. 'Save' the file.
  5. Change the file permission level of the settings.php
    file on your server from "0444" to "0777";
    otherwise you will not be able to over-write it with
    the newly saved file you have on your computer.

    In the case of my Drupal 7 installation being on my webhost...
    1. I go to my online webhost account's control panel (CPanel)
    2. Click on the link for the 'File Manager'.
    3. Navigate to the file [Drupal 7 root]/sites/default/settings.php
    4. Change the file permission from 0444 to 0777.

      This might take some poking around for you to figure
      how to do it, but it should be easy enough once you
      find the right thing to click.

      In my case, double-clicking on the "0444" allowed me
      to edit the number right there, although
      you should also be able to change the permission number
      by highlighting the file, and clicking a button or link
      called "Change Permissions"; or similar.

  6. Replace the Drupal 7 settings.php file with the one you modified
    by an upload of the file settings.php that you have on your computer
    to the proper location on your webhost server
    using either your control panel (CPanel)
    or your FTP program.
  7. Change the permission level for the file back to 0444

Additional notes:

  • You can see the amount of memory you are being allowed by going to
    'Reports' > 'Status report'; and scrolling down to "PHP memory limit".

    It should read '512M' if you have followed the above steps.
  • Replacing the modified settings.php file on my website
    with a copy of the original settings.php file
    returned the "PHP memory limit" to what it had been before.
  • I have read that "Restarting the server" is required for local installations
    although I have no experience with that.

All the best.

Memory Overload: php.ini vs settings.php solutions

Working with Greengeeks, Drupal 7.2, I was regularly receiving memory warnings when loading or activating modules. The result was that several modules were only partly activated.
The php.ini solution to add memory brought a white screen up, so I quickly removed that file.
The settings.php solution worked fine.
I'm sorry, I'm not geeky enough to work out why the php.ini solution failed, so this is just a warning; with some hosts, it doesn't work!

The settings.php file did not work for me

Hi. I am having touble with this message: Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access temporary://small.jpg in file_save_upload(
I think it is to do with my memory limit. I have already increased to 128m and now with pics I am having this problem. I'll looked up the posts on the error message and they have not helped. I'd like to increase to 512m to see if it will help but your suggestion hasn't worked for me. Any other ideas would be valuable.

All,
There are 2 ways of running php: As an apache module or as a cgi. If your host runs php as an apache module, adding your own php.ini will not work. *Most* web hosts are running php as a cgi. If you are running Apache locally on your machine or you have access to the main server php.ini file, you can change the memory limit there. That does, however, require restarting Apache as mentioned above. Most shared hosts will not allow you do this, which is why using the settings.php method is easier. That changes the memory limit "on the fly".

In Linux, the command is typically "/etc/init.d/httpd restart" ( use apache instead of httpd if you're on Ubuntu ). Some systems may also conveniently support this command "service httpd restart" (again, replace with apache if you're on ubuntu).

On cpanel if you have whm access you can restart apache from the services restart menu.

On Xxamp you can restart the services from the control panel tray.

I'm not sure how to restart IIS.

Hope this helps.

thanks for help finally after

thanks for help
finally after 2 months it has been fixed.

New php.ini

New php.ini solution worked in the root dir. Thanks a bunch!

Drupal Themer

with the 512M my site has solved the problem

I ve got the same problem with the memory
once the error is hint of includes.php
other time with many other modules
but I hope this time will stay ok since i ve fixed the memory to :512M
for :
HTACCESS
SETTINGS.PHP
PHP.INI
thanks

wordtosay

facebook

http://www.facebook.com/#!/hmimid

Twitter

https://twitter.com/#!/word_to_say

Gmail

mhamed.hmimid@gmail.com

Skype

mhamed.hmimid

PHP Memory Limit drupal 7.7

So after hacking around for hours i finally found a solution.
1- Deleted "everything".
2- created a php.ini file with the following text

memory_limit = 512M
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so

4 Did "not edit" htaccess, settings .php or defaultsettings php
5 installed drupall 7.7 as usual and wallah php memory was set.

What I found that worked for increasing PHP memory for D7 & D6 to 128MB
at my online websites (bluehost.com) was the php.ini solution outlined in...
Drupal 7 "Fatal error: Allowed memory size of ..."
http://drupal.org/node/76156#comment-4582924

To my knowledge, all you would have had to put in your php.ini file was
php_value memory_limit = "128M"

But I see that the multiple lines of code you used in your php.ini file
are addressed at... Increase PHP memory limit
http://drupal.org/node/207036

To my knowledge, increasing the 128 to either 256, or 512
does not cause problems, but it gives me only 128MB of memory
and that is the limit of php.ini per my experience.

So, please, I am curious if you are using D7,
and whether you can tell me if you in fact
did achieve 512MB with php.ini using
memory_limit = 512M.

You can see the amount of memory you are being allowed by going to
'Reports' > 'Status report'; and scrolling down to "PHP memory limit".

What do you have, please?

===

And, by the way, although I have yet to need more than 128MB yet, I did successfully get
512MB using the process delineated in the comment above ...

Drupal 7 memory increase to more than 128M
http://drupal.org/node/76156#comment-4583384

by Adding the line
ini_set('memory_limit', '512M');
to the very bottom of the [Drupal 7 root]/sites/default/settings.php file.

I found it interesting that the setting.php solution
was necessary according to the comment above....
Why the php.ini solution doesn't work for some users
http://drupal.org/node/76156#comment-4761114

(Although I never tried the settings.php on D6
since I have not been back to D6 since finding that solution)

===

Am I deceiving myself?

I think that DAMP runs faster on my computer
with the php.ini memory solution file thrown into my D7 root?

Does anyone know if my perception of speed increase is mistaken
or unlikely?

php.oni magic!

just to confirm that adding ArchDoomBringer's code from the post above has fixed the pdo problem I was having. Thanks.

cheers,
allanx
perth - western australia
---
web design | development | maintenance: http://radicalhack.com

For german Users / Fuer deutsche Nutzer

Instructions in german / deutsche Anleitung:

http://shajkovci.net/node/11

Still doesn't work for me

I tried to create new php.ini, I also tried to add that line into settings.php. In Status report the PHP memory limit says 512.

And I'm still getting the Fatal error, almost every time after running update.php.

Any idea please?

APC and PHP aren't the same thing

If you have APC turned on, usually this indicates that the PHP code caching that APC does is full. In that case, you need to update the APC memory *not* necessarily the PHP memory. Make sense? APC usually has its own config file.

Page status

Needs updating

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Developers and coders, Site administrators

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.