脚本宝典收集整理的这篇文章主要介绍了从cli运行PHP脚本:php.ini memory_size没有考虑到,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
为了解决这个问题,我编辑了/etc/PHP5/cli/PHP.ini文件并设置了memory_limIT = 2048M.
要检查配置,我运行一个包含PHPinfo()的脚本;从cli我看到:memory_limit => 2048M => 2048M,因此似乎正确考虑了配置. ini_get(‘memory_limit的);也返回2048M.
但是当我重新运行reindex脚本时,我仍然得到PHP致命错误:允许的内存大小为536870912字节,因为memory_limit仍然是512M.该脚本无法完成,我没有想法如何扩充memory_limit以允许脚本完成.
编辑:我也尝试添加指令ini_set(“memory_limit”,-1);直接进入PHP脚本,它仍然挂起相同的PHP致命错误:允许的内存大小为536870912字节耗尽.
额外的信息:
服务器是运行Debian GNU / Linux 7.5和64GB Ram的ovh专用机器!
PHP -v返回:
脚本执行期间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设置内存限制.我编写了这个PHP脚本,我从cli运行以替换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(); ?>
仍然得到同样的错误.
/** * Parse .htaccess file and apply PHP settings to shell script * */ 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',$match[2])); } } } }
解
不要通过.htaccess设置内存限制和执行时间,使用PHP.ini或虚拟主机配置.
以上是脚本宝典为你收集整理的从cli运行PHP脚本:php.ini memory_size没有考虑到全部内容,希望文章能够帮你解决从cli运行PHP脚本:php.ini memory_size没有考虑到所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。