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?