Allowed memory exhausted Magento shell script

9th May 2014

So I was working with an import script that was built using Mage_Shell_Abstract. There are actually a few benefits when extending from that class, primarily that the Magento initialisation is done for you.

At some point my import script crashed saying:

PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 8192 bytes) in /home/example/public_html/lib/Zend/Cache/Backend/File.php on line 962

What puzzled me was that the memory_limit setting for CLI is set to -1. Turns out Mage_Shell_Abstract actually parses your .htaccess for php_value entries.

In this case there was a php_value memory_limit 1024M set in the .htaccess causing our import to have that limit.

So you can choose to either increase the memory_limit in your .htaccess:

php_value memory_limit 2048M

Or increase it in your run function.

class Twm_Shell_Products extends Mage_Shell_Abstract
{
    public function run()
    {
        ini_set('memory_limit', '2048M');
    }
}

I'm not sure what Magento was thinking, I understand they want to make it easier for the users but this is highly unusual behavior and quite confusing.

comments powered by Disqus