Symfony2 Doctrine2 exceeding memory limit, Allowed memory size of 1073741824 bytes exhausted

StackOverflow https://stackoverflow.com/questions/19657873

Domanda

I have a relational database for posts.

Post Table <-- OneToMany

Post cat Table <-- ManyToOne

Category Table <-- OneToMany

If I use the Doctrine @ORM to join the tables, in Entities using annotation. I get a white screen and in the error logs show the error:

emergency.EMERGENCY: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1052508160 bytes) {"type":1,"file":"/[PATH TO SYMFONY]/vendor/twig/twig/lib/Twig/Extension/Debug.php","line":66}

I have upped the memory limit several times, from 64M to 1024M.

Has anyone else found this problem? I think that a file executing > a Gig of memory is no good.

If I write the query using the query builder I get the results I expect. I think if I could get the Doctrine relational mapping to work this would be better. does any one have an opinion on this?

I would love a bit of advice on this matter.

Thanks In advance.

Joe

------------ Edit in response to comment ---------------------------------------

Thanks for your comment @Cerad. There are only about 10 rows in the database. Also i'm in app_dev.php. Here are some excerpts form my files.

post table

class Post
{
    //... ^ table collumns

    /**
     * @ORM\OneToMany(targetEntity="PostCats", mappedBy="Post")
     */
    protected $PostCats;

    public function __construct()
    {
        $this->PostCats = new ArrayCollection();
    }

}

post cat joining table.

class PostCats
{
    //... ^ table collumns

   /**
     * @ORM\ManyToOne(targetEntity="Post", inversedBy="PostCats")
     * @ORM\JoinColumn(name="postid", referencedColumnName="id")
     */
    protected $Post;

}

the controller

$posts = $this->getDoctrine()
    ->getRepository('comPostBundle:Post')
    ->find(7);
if (!$posts) {
    throw $this->createNotFoundException(
        'No product found for id '.$posts
    );
}
return new Response(print_r($posts))

Result.... White screen... I have also tried returning the results dumped into a twig template.

Do you think its ok to skip the Doctrine relational mapping and just write joins in the entity repositories?

È stato utile?

Soluzione

So The problem has been solved thanks to @Cerad.

The issue was that I was ether doing a print_r() in the PHP, or a {{ dump() }} in the twig template. these functions do not like entities or displaying large arrays/objects.

now I am just calling what parts of the returned values I want and not dumping the whole data. and it works fine!.

EDIT:

This works for dumping data

\Doctrine\Common\Util\Debug::dump($object);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top