Increasing the PHP Memory Limit

Today I needed to run a some code that did a lot of heavy lifting and kept having the error below:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 71 bytes) in /Applications/MAMP/htdocs/test_memory.php on line 46

The solution is to override the memory limit set by PHP.ini:

<?php
ini_set('memory_limit','64M');

Check out PHP.Net’s ini_set documentation for more details.

Notes:

  • This has be done as one of the first commands in your PHP file
  • You may need to have to increase the limit to more if the problem is still occurring
  • If this is unexpected there may be some really inefficient code in your code base
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s