php - Symfony2 Templating renderResponse causing CPU usage to shoot up -


i have job loops through users , sends personalized email based on preferences. using templating engine in symfony2 generate html.

basically runs in loop:

public function gethtml($user)  {     $templating = $this->getcontainer()->get('templating');     $html = $templating->renderresponse(                  'recommendation.html.twig',                  array(                    'user' => $user                  )              )->getcontent();     return $html; } 

the problem cpu usage shoots 100% , takes longer , longer process each user. here data:

took 5.4851469993591 seconds  took 12.790720939636 seconds  took 23.007503032684 seconds  took 34.852293014526 seconds  took 43.901736021042 seconds  took 66.028288125992 seconds  

each line represents time taken process 100 users. first 100 users took 5 seconds, next 12 seconds, , on.

any suggestions on can improve performance?

it'll doctrine accumulating massive identity map of managed entities fetch them.

in each iteration of email send, @ doing entity manager clear or detach

best use in combination iterated result, there's good example in documentation.

it can make huge difference speed , memory consumption jobs large amount of iterations.

doctrine isn't great long running scripts without bit of work.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo