[英]doctrine and large amount of data
我有一个返回~50k行的查询,看起来像doctrine将整个结果放入内存超出内存限制(128M)我找到的唯一解决方案是节省一些内存
$result->execute(array(), Doctrine_Core::HYDRATE_NONE);
但是它仍然超出了限制,有没有办法一次用学说阅读一行?
Doctrine Documentation - 13.批处理
更新:对于1.2,请查看此页面: http : //docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/data-hydrators.html
在“按需”标题下,您将找到答案。
批处理有帮助!
我花了很长时间才弄清楚有什么帮助。 我的印象是,只要你保持相同的php进程你就无法释放你的记忆。 所以这对我没有帮助 :
真正有用的是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)
对此主题的任何评论或批评都非常感谢,因为这对我来说很难!
你有没有使用 - > limit()和 - > offset()的原因?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.