What should I do if symfony propel doselect memory overflows?
漂亮男人
漂亮男人 2017-05-16 16:46:11
0
1
463

When symfony propel doselect, what should I do if the data taken out at one time is too large and causes memory overflow?

漂亮男人
漂亮男人

reply all(1)
我想大声告诉你

Using doSelect will take out all the rows at once and throw them into the memory. If your result set is relatively large, it will naturally explode; you can use row-by-row operation to control the memory peak:

/* 方法1.a */
$stmt = YourPeer::doSelectStmt($criteria); // <= 预处理
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    // 逐行操作$row
}

/* 方法1.b */
$rs = YourPeer::doSelectRS($criteria); // <= 取回一个打了包装的结果集
$rs->setFetchMode(ResultSet::FETCHMODE_ASSOC);
while($rs->next()) {
    $row = $rs->getRow();
    // 逐行操作$row
}

There are also some lazy ways that don’t cure the symptoms:

/* 方法2:如果不需要把数据结果映射成对象,可以只获取指定的字段;不映射成对象,也能省内存 */
$criteria = new Criteria();
$criteria->clearSelectColumns()->addSelectColumn(YourPeer::COL_NAME);
// 然后⋯⋯

/* 方法3:在php.ini里增大PHP运行内存限制 */
memory_limit = 1111M
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template