7

Before reply please read scenario on Magento 1.8.X

command

php  indexer.php --reindex all
Product Attributes index was rebuilt successfully
Product Prices index was rebuilt successfully
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 128 bytes) in  /home/zeleyane/public_html/naturjoya.com/lib/Varien/Object.php on line 117

Information PHP

php -i | grep memory
memory_limit => 512M => 512M
Collecting memory statistics => No
suhosin.memory_limit => 0 => 0

Try put on index.php

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

I think there're any file of Magento with limit 512M.

Try looking for 256 or 268435456 on files, I don't see a correct file.

1 Answer 1

19

The problem comes from .htaccess. One of the values is php_value memory_limit 256M. This doesn't make sense on the first view, but on the second it is explainable.

I don't know why magento implemented this idiot thing, but what happend is, the following method reads the information from .htaccess and processes them:

\Mage_Shell_Abstract::_applyPhpVariables
protected function _applyPhpVariables()
{
    $htaccess = $this->_getRootPath() . '.htaccess';
    if (file_exists($htaccess)) {
        // parse htaccess file
        $data = file_get_contents($htaccess);
        $matches = array();
        preg_match_all('#^\s+?php_value\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
        if ($matches) {
            foreach ($matches as $match) {
                @ini_set($match[1], str_replace("\r", '', $match[2]));
            }
        }
        preg_match_all('#^\s+?php_flag\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
        if ($matches) {
            foreach ($matches as $match) {
                @ini_set($match[1], str_replace("\r", '', $match[2]));
            }
        }
    }
}
2
  • 2
    a lot of thanks. I don't know this stupid limit on .htaccess... Also see any files on magenta with 256M limitations... incredible. Oct 8, 2014 at 20:26
  • 2
    For anybody skipping over this answer thinking I'm using Nginx, .htaccess doesn't apply to me... - check there isn't a redundant, unused .htaccess file in the root. The method shown above by Fabian means that whilst the .htaccess file isn't being used by the server, the data is being read via PHP.
    – McNab
    Mar 10, 2017 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.