title: run PHP script from cli : php.ini memory_size not taken into account
body: <p>I am trying to run a php script (magento reindexer script) from the command line. The script consumes a lot of memory so I am getting the following error: <code>PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 72 bytes) in /home/karanta/www/karanta.fr/lib/Zend/Db/Adapter/Abstract.php on line 691</code></p>
  
  <p>To fix this issue, I edited the <code>/etc/php5/cli/php.ini</code> file and set <code>memory_limit = 2048M</code>.</p>
  
  <p>To check the configuration, I run a script containing <code>phpinfo();</code> from the cli and I see: <code>memory_limit =&gt; 2048M =&gt; 2048M</code>, so it seems the configuration is taken into account properly. <code>ini_get('memory_limit);</code> also returns 2048M.</p>
  
  <p>However when I rerun the reindex script, I still get <code>PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted</code> as if the memory_limit was still 512M. The script is unable to complete, I am out of ideas how to augment the memory_limit to allow the script to complete.</p>
  
  <p>Edit: I also tried adding the instruction <code>ini_set("memory_limit", -1);</code> directly into the PHP script and it still hangs with the same <code>PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted</code>.</p>
  
  <p>Extra information:</p>
  
  <p>Server is a dedicated machine at ovh running Debian GNU/Linux 7.5 with 64GB RAM!</p>
  
  <p><code>php -v</code> returns:</p>
  
  <blockquote>
    <p>PHP 5.6.12-1 (cli)  Copyright (c) 1997-2015 The PHP Group Zend Engine
    v2.6.0, Copyright (c) 1998-2015 Zend Technologies
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies</p>
  </blockquote>
  
  <p><code>free -k -h</code> during script execution returns:</p>
  
  <pre><code>               total        used        free      shared  buff/cache     available
  Mem:            62G        1,8G         48G         84M          12G         60G
  Swap:          1,0G          0B        1,0G
  </code></pre>
  
  <p><code>ps -aux</code> returns:</p>
  
  <pre><code>karanta  25568  5.6  0.0 229484 41824 pts/1    S    07:54   0:04 php shell/indexer.php --reindex catalog_url
  </code></pre>
  
  <hr>
  
  <p>Following @IgorGreg's recommandation, I tried setting the memory limit using Zend_Memory. I wrote this php script that I run from the cli in replacement of the shell/indexer.php script.</p>
  
  <pre><code>&lt;?php
  require_once 'app/Mage.php';
  $app = Mage::app('admin');
  umask(0);
  $memoryManager = Zend_Memory::factory('none');
  $memoryManager-&gt;setMemoryLimit(-1);
  $process = Mage::getModel('index/process')-&gt;load(3);
  $process-&gt;reindexAll();
  ?&gt;
  </code></pre>
  
  <p>Still getting the same error.</p>