Doctrine Huge Collections Performance Tip
Doctrine 1.x have a lot of performance problem. In last year I was forced to use it and had a lot problems.
If you need to write big tasks or migrations with tons of doctrine object you can try to utilize php garbage collector.
First try
foreach ($collection as $object) {
// some code
unset($object);
}
Unfortunately object have circular references, and garbage collector cannot handle this.
Proper way
foreach ($collection as $object) {
// some code
$object->free(true);
unset($object);
}
Doctrine objects, collections and query have free method. If you pass true, method will recursively free all references. Now php garbage collector work fine and even huge synchronize task can be exeuted in one run.
Written by Tomasz Ślązok
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Did you know?
PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#