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

Joe*_*Joe 2 memory-limit symfony doctrine-orm

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

帖子表 <-- 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}
Run Code Online (Sandbox Code Playgroud)

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

还有其他人发现这个问题吗?我认为执行> Gig 内存的文件是不好的。

如果我使用查询生成器编写查询,我会得到我期望的结果。我认为如果我能让 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();
    }

}
Run Code Online (Sandbox Code Playgroud)

后猫加入表。

class PostCats
{
    //... ^ table collumns

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

}
Run Code Online (Sandbox Code Playgroud)

控制器

$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))
Run Code Online (Sandbox Code Playgroud)

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

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

Joe*_*Joe 5

感谢@Cerad,问题已经解决。

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

现在我只是调用我想要的返回值的哪些部分,而不是转储整个数据。并且效果很好!

编辑:

这适用于转储数据

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