2014-04-08 14:34
浏览 59


I have issues with symfony 1.4 a task running daily. To make simple the task download an xml then read it.

I have notice that the memory used increase between each "node" in the xml.

For instance, somewhere in the script I do that:

 foreach($prd->ArtistList->Artist as $art)
  echo "start foreach artist  ", memory_get_peak_usage(1), " bytes of ram.
            if(!$artist = ArtistTable::getInstance()->findOneByRoleAndName($art['role'], $art['name']))
              $artist = new Artist();
              $artist->role = $art['role'];
              $artist->name = $art['name'];

            if(!$pha = ProductArtistTable::getInstance()->findOneByProductIdAndArtistId($prd_id, $artist->id))
              $pha = new ProductArtist();
              $pha->product_id = $prd_id;
              $pha->artist_id = $artist->id;


            echo "end foreach artist  ", memory_get_peak_usage(1), " bytes of ram.

I can see that between two memory_get_peak_usage(1) end and start, memory used increase... I don't know what else am I supose to do to keep it at a same level...

Do you have any idea how to solve that?


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshan7060 2014-04-08 15:35

    I've monitored slow performances in the past within a symfony application. Found out that those built in ORM's (Doctrine in my case) query methods are really a bad thing, especially within a foreach loop.

    I'd suggest you to try using RAW SQL instead.

    If you don't know how to use raw sql within symfony this should do the trick

    $connection = Doctrine_Manager::connection();
    $statement = $connection->prepare('your sql statement');
    $result = $statement->fetchAll(PDO::FETCH_NUM); // or whatever fetch mode you want to use
    解决 无用
    打赏 举报

相关推荐 更多相似问题