Symfony2 Doctrine2超出内存限制,允许的内存大小为1073741824字节耗尽

时间:2013-10-29 12:10:09

标签: symfony doctrine-orm memory-limit

我有一个帖子的关系数据库。

帖子表< - OneToMany

邮政猫表< - ManyToOne

类别表< - OneToMany

如果我使用Doctrine @ORM连接表,则使用注释在实体中。我得到一个白色的屏幕,并在错误日志中显示错误:

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}

我已经多次提高了内存限制,从64M增加到1024M。

有没有人发现这个问题?我认为执行的文件>记忆力不好。

如果我使用查询构建器编写查询,我会得到我期望的结果。我想如果我能让Doctrine关系映射工作,那就更好了。有没有人对此有意见?

我会对这件事情提出一些建议。

提前致谢。

------------编辑以回应评论------------------------------ ---------

感谢您对@Cerad的评论。数据库中只有大约10行。我也在app_dev.php。 以下是我的档案中的一些摘录。

发表表格

class Post
{
    //... ^ table collumns

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

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

}

邮寄猫加入表。

class PostCats
{
    //... ^ table collumns

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

}

控制器

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

结果......白屏...... 我也尝试将结果转储到树枝模板中。

你认为可以跳过Doctrine关系映射并只在实体存储库中编写连接吗?

1 个答案:

答案 0 :(得分:3)

所以@Cerad已经解决了这个问题。

问题在于我在PHP中执行print_r(),或在twig模板中执行{{dump()}}。这些函数不喜欢实体或显示大型数组/对象。

现在我只是调用我想要的返回值的哪些部分而不是转储整个数据。它工作正常!。

编辑:

这适用于转储数据

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

相关问题