doutan8601 2014-04-08 14:34
浏览 61
已采纳

symfony任务中的内存泄漏

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'];
              $artist->save();
            }

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

            $pha->free(true);
            $artist->free(true);
            unset($pha);
            unset($artist);

            echo "end foreach artist  ", memory_get_peak_usage(1), " bytes of ram.
";
          }
          unset($art);

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?

Thanks!

  • 写回答

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');
    $statement->execute();
    $result = $statement->fetchAll(PDO::FETCH_NUM); // or whatever fetch mode you want to use
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c