简体   繁体   中英

Symfony/doctrine consuming to much memory, out of memory error

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 ...

The data i'm retrieving is 300KB at most. In this case I'm using a route to retrieve a list of project (600B) , it's one of the smallest table. This table has two OneToMany associations.

数据库看起来像这样

The data i'm retrieving looks like this :

[
  {
   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"
  }
]

The doctrine's querybuilder and the function :

    public function findAllProject()
    {
        return $this->createQueryBuilder('p')
            ->select('p.id', 'p.name', 'p.description', 'p.project_date_start', 'p.project_date_end')
            ->getQuery()
            ->getResult()
        ;
    }
        public function project(Request $request)
        { 
            $em = $this->getDoctrine()->getEntityManager();

            $projectRepo = $this->getDoctrine()->getRepository(Project::class);

            $project = $projectRepo->findAllProject();

            $data = $this->get('jms_serializer')->serialize($project, 'json');

            $response = new Response($data);
            $response->headers->set('Content-Type', 'application/json');
            $response->headers->set('Access-Control-Allow-Origin', '*');

            return $response;
        }

I've tried :
- reinstalling Apache on the server
- changing the value of the memory_limit in the php.ini
- not using jms_serialiser and using json_encode instead

EDIT

So the error is definitly not comming from the serializer, since the error is thrown while i'm getting the data from the repository ( findAllProject() ).

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 project is one of the smallest table, so what about when I need the retrieve bigger data ?

If i'm getting data back from symfony, maybe it's not symfony but apache, what could cause this error ?

Also, the generated SQL comming from the queryBuilder is good (juste a normal select)

END EDIT

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).

I think the association of the project table is messing up everything and doctrine is trying to go throught all the database. Maybe a problem with the design of my database ?
For exemple, the table type is the same size as project but don't have the out of memory error.

I don't know what else I can try, any idea ?

因此,我从头开始重新安装了服务器,然后重新启动了项目,该服务器正常运行,所以我不知道是什么导致了此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM