Yii2 db \连接内存耗尽

时间:2015-07-14 12:31:16

标签: php out-of-memory yii2

我的代码相当复杂,但它的作用是:读取csv文件,对数据执行一些操作,选择并向db插入数据。所有操作都以块的形式完成,所有变量都被重用,并且它们都不是全局变量。 错误看起来像这样(显示完整的堆栈跟踪):

[bt704cdb0e1fhr6jbf5q1hg2r4][error][yii\base\ErrorException:1] exception 'yii\base\ErrorException' with message 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 332653 bytes)' in /usr/sites/autozapas/vendor/yiisoft/yii2/db/Connection.php:782
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
2015-07-14 14:17:23 [2][bt704cdb0e1fhr6jbf5q1hg2r4][info][application] $_POST = [
    'columns' => '{}'
    'comment' => ''
    'supplier_id' => ''
]

在某些阶段,应用程序因此错误而停止。成功执行了超过半个块。我通过以下方式执行数据库操作:

$connection = Yii::$app->dbData;
$command = $connection->createCommand($sql);
$command->queryAll(); //or $command->execute();

yii2 \ db \ Connection.php中抛出错误的部分:

public function quoteSql($sql)
    {
        return preg_replace_callback(
            '/(\\{\\{(%?[\w\-\. ]+%?)\\}\\}|\\[\\[([\w\-\. ]+)\\]\\])/',
            function ($matches) {
                if (isset($matches[3])) {
                    return $this->quoteColumnName($matches[3]);
                } else {
                    return str_replace('%', $this->tablePrefix, $this->quoteTableName($matches[2]));
                }
            },
            $sql
        );
    }

我不使用这个函数,我的所有块都有相同的sql字符串。改变块的大小没有帮助。对不起,我无法显示代码并寻找建议什么样的代码可以产生这样的错误。

有人有同样的问题吗?

0 个答案:

没有答案
相关问题