2008-01-02

Fatal error: Allowed memory size of xxx bytes exhausted

Happy New Year to all!

2007 is already the past now. I hope I can keep writing in this new year 2008, not so lazy like in 2007. :)

So today's topic is a PHP error.

During a migration of a Drupal site, after I make a 100% copy of the test site to the new site and change every settings for the new one, then the new site shows me the terrible message!
Fatal error: Allowed memory size of 654321 bytes exhausted (tried to allocate 12345 bytes) in /srv/www/user/bla/blub/file.php on line 123
What goes wrong? The test site runs like a charm and the process of migration should be okay.

In PHP, there is a enviroment variable called memory_limit. It varies by your web hosting provider. By default it's 128M, namely 128 MB memory. Since the web hosting provider want to spare some hardware costs and provides more accounts on a shared server, so the value of memory_limit will be changed to 16M sometimes! If you are like me to use some modules in Drupal (that's what makes Drupal attractiver than others!), because every module will eat some memories, so your Drupal installation will reach the memory limit very soon!

Now here is the solution:

  1. Contact your web hosting provider to beg them for a bigger memory_limit, which is hard to be satisfied.
  2. Try to switch off some Drupal modules to save the memory. It can be done only through Database manipulation such as in PHPMyAdmin.

If you have to choose the second way:

Go to the table "system", you will find almost every module has a feld called "status". 0 means not selected, 1 means enabled. Try to set the status of some modules such as statistic, color, etc to 0. After that you should see your new site without the above error. If not, eh.... you must switch more modules off. What a pity!

Most important, after the DB manipulation you should go to administer -> site configuration -> modules to save your configuration and run the update.php, otherwise the Drupal will lose some module-special configuraions.

No comments: