Doctrine 查询执行内存问题
Doctrine query execution memory issue
我是运行循环中的学说查询,绑定参数并执行多次。查询执行得很好,问题是每组循环的内存使用量增加了大约 3mb。垃圾收集似乎没有启动,最终服务器内存不足。
foreach () { .....
foreach () { .....
$conn = $this->getEntityManager()->getConnection();
if ($this->sql == null) {
$this->sql = $conn->prepare(
"INSERT INTO table (l_id, a_id) VALUES (:lId, :aId);"
);
}
//Memory usage 200
foreach($lo as $l) {
$this->sql->bindParam('lId', $l->getId());
$this->sql->bindParam('aId', $aId);
$this->sql->execute();
}
//Memory usage ++3mb
}
}
整个脚本也嵌套在一个循环中。所以它会被调用很多次。但是上面的foreach循环好像是内存增加的地方
我调用直接插入数据库,所以实体管理器甚至没有使用,因为最初我认为这可能会减慢它的速度。
编辑:
我试过将 bindParam 更改为 bindValue 但出现了同样的问题。并将第二个 bindParam 移到循环外;
通过关闭 SQL 登录原则,内存泄漏问题得到解决,考虑到此应用程序中被触发的查询数量,
$conn = $this->getEntityManager()->getConnection();
$conn->getConfiguration()->setSQLLogger(null);
我是运行循环中的学说查询,绑定参数并执行多次。查询执行得很好,问题是每组循环的内存使用量增加了大约 3mb。垃圾收集似乎没有启动,最终服务器内存不足。
foreach () { .....
foreach () { .....
$conn = $this->getEntityManager()->getConnection();
if ($this->sql == null) {
$this->sql = $conn->prepare(
"INSERT INTO table (l_id, a_id) VALUES (:lId, :aId);"
);
}
//Memory usage 200
foreach($lo as $l) {
$this->sql->bindParam('lId', $l->getId());
$this->sql->bindParam('aId', $aId);
$this->sql->execute();
}
//Memory usage ++3mb
}
}
整个脚本也嵌套在一个循环中。所以它会被调用很多次。但是上面的foreach循环好像是内存增加的地方
我调用直接插入数据库,所以实体管理器甚至没有使用,因为最初我认为这可能会减慢它的速度。
编辑: 我试过将 bindParam 更改为 bindValue 但出现了同样的问题。并将第二个 bindParam 移到循环外;
通过关闭 SQL 登录原则,内存泄漏问题得到解决,考虑到此应用程序中被触发的查询数量,
$conn = $this->getEntityManager()->getConnection();
$conn->getConfiguration()->setSQLLogger(null);