Allowed memory size bytes exhausted: eZ platform import contents [duplicate]

  ezplatform, memory, memory-limit, php, symfony

Hello guys I have a kind of symfony command that import data from a CSV file and display an output for each line. Weather the line has been sucsufflly imported or not.
the command does 3 things mainly:
1. recover data from a csv file line.
2. encapsulate them with a DTO object.
3. persist them in the database.
4. Reindex the object in solr and delete the cache pool.

The command works without any issue for 400 lines. But when the the csv contain more lines the command will be killed and a

PHP Fatal Error: Allowed Memory Size Exhausted …bytes exhausted (tried to allocate…)

will be throwed.

This a part of my code.

class ImportCSVCommand extends Command
// more then 20k lines
        foreach ($line as $lines) {
            try {
                $fields = $this->getFieldsFromLine($line);
                $draft = $contentService->createContent( $contentCreateStruct, array( $locationCreateStruct ) );
                $content = $contentService->publishVersion( $draft->versionInfo );
                $output->writeln('line has been  successfully imported');
            } catch (Exception $e) {
                $output->writeln('c"ant  importe line ...' ));


Most of the time when I work with clip migration PHP scripts, even with 20k contents, I don’t get any CPU problems. But with the symfony command I get the exception because it consume a lot of CPU.

I already tried to execute with php -d memory_limit=-1 but didn’t work great. I’m asking if there’s any idea to optimize my symfony command, if there any solution that can help me to improve.

Any serious help would be appreciated and voted.

Source: Symfony Questions