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