douzhan1994 2014-03-19 09:40
浏览 55
已采纳

为什么php脚本会变慢?

I was working on migration scripts which selects data from one MySQL database and import through doctrine into another MySQL database. The problem was that after every chunk of created entities, my scripts slowed down.

first 100 articles takes about 5 seconds to import, next 100 articles takes 7 seconds, next 10 seconds and so on. It is really big problem, because I need to import about 1.500.000 articles.

  • 写回答

1条回答 默认 最新

  • dongpu2727 2014-03-19 09:41
    关注

    I found out that php >=5.3 has garbage collector cleaner. So, when I import chunk of articles I call gc_collect_cycles(); to clear memory out of all entities which script will needs no more. The script is slowing down no more!

    If you are using a framework, check if it has its own cache system. If you are using doctrine turn off SQL logger

    /** @var $em EntityManager */
    $em = $this->getContainer()->get('doctrine')->getEntityManager();
    $em->getConnection()->getConfiguration()->setSQLLogger(null);
    

    and then clear doctrine cache after every chunk is imported

    $em->clear();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么