簡體   English   中英

學說和大量數據

[英]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進程你就無法釋放你的記憶。 所以對我沒有幫助

  • $對象 - >免費(真)
  • 未設置($對象)
  • sfConfig :: set('sf_debug',false)
  • gc_collect_cycles()/ gc_enable()
  • Doctrine_Core :: HYDRATE_ON_DEMAND
  • sfCommandApplicationTask :: runTask()
  • sfDoctrinePager

真正有用的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM