【问题标题】:Allowed memory size in MagentoMagento 中允许的内存大小
【发布时间】:2013-10-16 08:46:03
【问题描述】:

问题:当客户登录并在管理面板中保存产品时,然后刷新前端并显示错误:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 88 bytes) in /home/staging/public/kralengroothandel/app/code/local/Zend/Db/Statement/Pdo.php on line 297

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 83 bytes) in /home/staging/public/kralengroothandel/lib/Varien/Simplexml/Element.php on line 196

Pdo.php 行,出现问题的地方:

public function _execute(array $params = null)
{
    try {
        if ($params !== null) {
            return $this->_stmt->execute($params);
        } else {
            return $this->_stmt->execute();
        }

第二名:

public function fetchAll($style = null, $col = null)
    {
        if ($style === null) {
            $style = $this->_fetchMode;
        }
        try {

            if ($style == PDO::FETCH_COLUMN) {

                if ($col === null) {

                    $col = 0;
                }
                return $this->_stmt->fetchAll($style, $col);
            } else {
                return $this->_stmt->fetchAll($style);
            }

元素.php:

 if (!$desc) {
     return false;
 }

我在本地机器上有相同的代码和数据库,但我没有这个问题。

memory_limit 设置在 512M 上,我想问题不在这里,因为 Zend_Db 库设置了内部内存限制。所以我尝试将ini_set('memory_limit', '1024M'); 放在Pdo.php 中,但这也无济于事。我有 OneStepCheckout 扩展(也许这是我遇到这个问题的原因)。我使用 Ngnix。也许有人有同样的错误?

我的服务器上的php-fpm.conf:

pm = dynamic
pm.max_children = 4
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 2

request_terminate_timeout = 0
request_slowlog_timeout = 0

chdir = /

php_admin_value[memory_limit] = 512M
php_admin_value[post_max_size] = 128M
php_admin_value[post_max_vars] = 64000
php_admin_value[max_execution_time] = 3600
php_admin_value[realpath_cache_size] = 16m

【问题讨论】:

  • 尝试在你的根目录下的.htasscess文件中设置内存限制,像这样“php_value memory_limit 1024M”
  • 我忘了说,我用的是ngnix。

标签: magento zend-framework memory-leaks


【解决方案1】:

增加 php.ini 的大小

php_value memory_limit 64M // add the memory limit here 
php_value max_execution_time 18000

【讨论】:

  • 我确实更新了,我需要把它放在我的 php-fpm.conf 文件的末尾吗?
  • 在您的 conf 文件下确保没有注释?就像如果某事以 # 开头,在更改尝试查看您的 phpinfo 文件后也将其删除
  • memory_limit in php.ini 2000+M and max_execution_time 超过 360 天,但仍然出现错误
【解决方案2】:

查看shell/abstract.php,了解 Magento 如何以编程方式配置 php:

/**
 * 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', $data, $matches, PREG_SET_ORDER);
        if ($matches) {
            foreach ($matches as $match) {
                @ini_set($match[1], str_replace("\r", '', $match[2]));
            }
        }
    }
}

它使用 php ini_set 指令,而不是 Zend 库方法,所以这是要走的路。

【讨论】:

    【解决方案3】:

    如果您没有服务器权限,请在 magento_root/index.php 文件中添加以下代码 在顶部。

        ini_set("memory_limit",'1024M');
    

    你不会再收到关于内存限制的错误:)

    干杯!!

    【讨论】:

    • 没有帮助,因为正如我之前写的 - Zend_Db 库设置了内部内存限制。
    • 我之前遇到过同样的错误。在 magento php 比较代码之前,您必须在 root/index.php 文件中编写代码。 ini_set('memory_limit','1024M');如果您仍然面临这个问题,请告诉我... if ( preg_match('/designer/', $_SERVER['REQUEST_URI']) ) { $ary = pathinfo($_SERVER['REQUEST_URI']); $ary = explode('designer', $_SERVER['REQUEST_URI']); header("HTTP/1.1 301 永久移动"); header("位置:http://".$_SERVER['HTTP_HOST']."/designer".$ary[1]);出口; }
    • 我把它写在比较之前或最上面,不管错误仍然存​​在。
    猜你喜欢
    • 1970-01-01
    • 2017-01-05
    • 2020-04-26
    • 2012-04-29
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    相关资源
    最近更新 更多