我有一个返回~50k行的查询, 似乎主义将整个结果放入内存超出内存限制(128M) 我找到的唯一解决方案是节省一些内存
$result->execute(array(), Doctrine_Core::HYDRATE_NONE);
但仍超出限制, 有没有办法一次用学说阅读一行?
答案 0 :(得分:6)
Doctrine Documentation - 13. Batch Processing
<强>更新强> 对于1.2,请查看此页面: http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/data-hydrators.html
在“按需”标题下,您将找到答案。
答案 1 :(得分:1)
批处理有帮助!
我花了很长时间才弄清楚有什么帮助。我的印象是,只要你保持相同的php进程你就无法释放你的记忆。所以对我来说没有帮助:
真正帮助的是a hint from Rich Sage谁建议生成子进程来执行部分工作。查询的限制和偏移量作为进程之间的参数给出。要逐行将$options['limit']
设置为1,但50也应该是一个很好的值:
<强> daddyTask.class.php 强>
[..]
$total = ItemTable::getInstance()->createQuery('i')->count();
for ($offset = 0; $offset < $total; $offset += $options['limit'] )
{
passthru(
sprintf('%s %s/symfony doTask --limit=%s --offset=%s', sfToolkit::getPhpCli(), sfConfig::get('sf_root_dir'), $options["limit"], $offset),
$returnVar
);
}
<强> doTask.class.php 强>
$items = ItemTable::getInstance()->createQuery('i')->limit($options['limit'])->offset($options['offset'])->execute();
foreach( $items as $item )
{
// ..do something with the item
$this->log( 'INFO: '.memory_get_peak_usage(true).' memory in use.' );
}
(我在PHP 5.3.10的Symfony 1.4框架中使用Doctrine 1.2)
对此主题的任何评论或批评都非常感谢,因为这对我来说很难!
答案 2 :(得分:0)
是否有理由不使用 - &gt; limit()和 - &gt; offset()?