【发布时间】:2015-09-13 08:38:23
【问题描述】:
我正在尝试从命令行运行 php 脚本(magento reindexer 脚本)。该脚本消耗大量内存,因此出现以下错误: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
为了解决这个问题,我编辑了/etc/php5/cli/php.ini 文件并设置了memory_limit = 2048M。
为了检查配置,我从 cli 运行了一个包含 phpinfo(); 的脚本,我看到:memory_limit => 2048M => 2048M,所以似乎正确考虑了配置。 ini_get('memory_limit); 也返回 2048M。
但是,当我重新运行重新索引脚本时,我仍然得到PHP Fatal error: Allowed memory size of 536870912 bytes exhausted,好像 memory_limit 仍然是 512M。脚本无法完成,我不知道如何增加 memory_limit 以允许脚本完成。
编辑:我还尝试将指令 ini_set("memory_limit", -1); 直接添加到 PHP 脚本中,但它仍然挂起相同的 PHP Fatal error: Allowed memory size of 536870912 bytes exhausted。
额外信息:
服务器是 ovh 的专用机器,运行 Debian GNU/Linux 7.5 和 64GB RAM!
php -v 返回:
PHP 5.6.12-1 (cli) 版权所有 (c) 1997-2015 The PHP Group Zend Engine v2.6.0,版权所有 (c) 1998-2015 Zend Technologies 使用 Zend OPcache v7.0.6-dev,版权所有 (c) 1999-2015,由 Zend Technologies 提供
free -k -h在脚本执行期间返回:
total used free shared buff/cache available
Mem: 62G 1,8G 48G 84M 12G 60G
Swap: 1,0G 0B 1,0G
ps -aux 返回:
karanta 25568 5.6 0.0 229484 41824 pts/1 S 07:54 0:04 php shell/indexer.php --reindex catalog_url
按照@IgorGreg 的建议,我尝试使用 Zend_Memory 设置内存限制。我编写了这个从 cli 运行的 php 脚本来代替 shell/indexer.php 脚本。
<?php
require_once 'app/Mage.php';
$app = Mage::app('admin');
umask(0);
$memoryManager = Zend_Memory::factory('none');
$memoryManager->setMemoryLimit(-1);
$process = Mage::getModel('index/process')->load(3);
$process->reindexAll();
?>
仍然遇到同样的错误。
【问题讨论】:
标签: php magento command-line-interface memory-limit reindex