title: Symfony/doctrine consuming to much memory, out of memory error
body: <p>I want to get data from a table and encode it in json. I'm using doctrine and the querybuilder to select the data I want (which is everything from the table basically). The problem is that in dev, everything work fine, but when I go to prod I get the error : PHP Fatal error : Out of memory ...</p>
  
  <p>The data i'm retrieving is 300KB at most. 
  In this case I'm using a route to retrieve a list of <em>project</em> (600B) , it's one of the smallest table.
  This table has two <em>OneToMany</em> associations.</p>
  
  <p><a href="https://i.stack.imgur.com/iQl9m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iQl9m.png" alt="The database looks like this"></a></p>
  
  <p>The data i'm retrieving looks like this :</p>
  
  <pre><code>[
    {
     id: "bar",
     name: "bar",
     description: "bar",
     project_date_start: "2022-01-01 00:00:00",
     project_date_end: "2019-05-21 12:19:27"
    },
    {
     id: "foo",
     name: "foo",
     description: "foo",
     project_date_start: "2021-02-02 00:00:00",
     project_date_end: "2022-02-02 00:00:00"
    }
  ]
  </code></pre>
  
  <p>The doctrine's querybuilder and the function : </p>
  
  <pre><code>    public function findAllProject()
      {
          return $this-&gt;createQueryBuilder('p')
              -&gt;select('p.id', 'p.name', 'p.description', 'p.project_date_start', 'p.project_date_end')
              -&gt;getQuery()
              -&gt;getResult()
          ;
      }
  </code></pre>
  
  <pre><code>        public function project(Request $request)
          { 
              $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
              $projectRepo = $this-&gt;getDoctrine()-&gt;getRepository(Project::class);
  
              $project = $projectRepo-&gt;findAllProject();
  
              $data = $this-&gt;get('jms_serializer')-&gt;serialize($project, 'json');
  
              $response = new Response($data);
              $response-&gt;headers-&gt;set('Content-Type', 'application/json');
              $response-&gt;headers-&gt;set('Access-Control-Allow-Origin', '*');
  
              return $response;
          }
  </code></pre>
  
  <p>I've tried :<br>
  - reinstalling Apache on the server<br>
  - changing the value of the memory_limit in the php.ini<br>
  - not using <em>jms_serialiser</em> and using <em>json_encode</em> instead</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So the error is definitly not comming from the serializer, since the error is thrown while i'm getting the data from the repository (<em>findAllProject()</em>).</p>
  
  <p>I've managed to make it work by reducing the data i'm retrieving, but it's not a solution since I need all the data and as I said <em>project</em> is one of the smallest table, so what about when I need the retrieve bigger data ?</p>
  
  <p>If i'm getting data back from symfony, maybe it's not symfony but apache, what could cause this error ?</p>
  
  <p>Also, the generated SQL comming from the queryBuilder is good (juste a normal select)</p>
  
  <p><strong>END EDIT</strong></p>
  
  <p>I don't think it's a problem with the json encoding part nor an apache server configuration problem (the memory limit is at -1).</p>
  
  <p>I think the association of the <em>project</em> table is messing up everything and doctrine is trying to go throught all the database. Maybe a problem with the design of my database ?<br>
  For exemple, the table <em>type</em> is the same size as <em>project</em> but don't have the out of memory error.</p>
  
  <p>I don't know what else I can try, any idea ?</p>