I just ran into the same problem, this is what fixed this for me:
- no debugging
As the OP points out in its answer, installing --no-debug (ex: php app/console <my_command> --no-debug ) is critical for performance / memory in symfony console commands. This is especially true when using Doctrine, because without it, Doctrine goes into debug mode, which consumes a huge amount of additional memory (which increases at each iteration). For more information, see the Symfony docs here and here for more information.
- okr = prod
You should also always indicate the environment. By default, Symfony uses the dev environment for console commands. Typically, dev not optimized for memory, speed, processor, etc. If you want to iterate over more than a thousand elements, you should probably use the prod environment (for example: php app/console <my_command> --no-debug ). See here and here for more information.
Tip. I created an environment called console , which I specifically configured to run console commands. The following is information on how to create additional Symfony environments .
php -d memory_limit = YOUR_LIMIT
If you are doing a large upgrade, you should probably choose how much memory is acceptable for its consumption. This is especially important if you think a leak may occur. You can specify the memory for the command using php -d memory_limit=x (ex: php -d memory_limit=256M ). Note: you can set the limit to -1 (usually the default for php cli) so that the command runs without memory limits, but this is obviously dangerous.
Well-formed console command for batch processing
A well-formed console command to run a big update using the tips above looks like this:
php -d memory_limit=256M app/console <acme>:<your_command> --env=prod --no-debug
Use Doctrine IterableResult
Another great thing about using Doctrine ORM in a loop is using the IterableResult doctrine (see Doctrine Batch Processing docs ). This will not help in the given example, but usually when performing such processing the query result is executed.
Print memory usage while running.
It can be very useful to keep track of how much memory your team consumes during its work. This can be done by displaying the response returned by PHP, built into the memory_get_usage () function.
Good luck
Collin Krawll Nov 19 '16 at 23:01 2016-11-19 23:01
source share