Why is php script slowing down?

≡放荡痞女 提交于 2020-01-02 04:33:09

问题


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:


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();


来源:https://stackoverflow.com/questions/22501641/why-is-php-script-slowing-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!