1

My code is rather complex, but what it does is: read csv file, perform some operations on data, select and insert data to db. All operations are done in chunks, all variables are reused and none of them are globals. Error looks like this (full stack trace is shown):

[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' => ''
]

At some stage application stops with this error. More than a half chunks were successfully executed. I perform db operations through:

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

The part in yii2\db\Connection.php where error thrown:

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
        );
    }

I do not use this function and all of my chunks have rather same sql strings. Changing the size of chunk doesn't help. I'm sorry, I can't show the code and looking for suggestion what kind of code can generate such error.

Does anybody had the same issue?

Sam Ivichuk
  • 999
  • 1
  • 10
  • 22
  • http://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml – Dency G B Jul 14 '15 at 13:29
  • When you say changing the size of chunk doesn't help, do you mean you can't even make a query on 1 row? I had a similar problem with running out of memory, i was using each() and thought that was efficient, but turns out PDO always fetches the whole result into memory unless you configure it differently, and then you can't run a new query until you're done with the old one. – Beowulfenator Aug 06 '15 at 22:13

0 Answers0