drip5880
drip5880
2015-05-14 05:05

symfony中的内存不足错误

已采纳

I'm currently working on Symfony project (const VERSION ='2.5.10') and I am using xampp. PHP version is 5.5.19.

My problem is everytime I run my dev environment I get an error :

OutOfMemoryException: Error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 3358976 bytes) in C:\xampp\htdocs\Editracker\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Profiler\FileProfilerStorage.php line 153

and everytime I refresh the page it gives different memory size. I also think that this is also the reason why my dev environment takes a lont time before it refreshes the page.

Your help is appreciated.

php.ini

memory_limit= '256M'

I tried to increase my memory limit,still it gives an error about memory limit

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • doubu8643 doubu8643 6年前

    The most eager component in Symfony is a profiler. If you don't need profiler in some particular actions you can disable it via code:

    if ($this->container->has('profiler'))
    {
        $this->container->get('profiler')->disable();
    }
    

    You can also set global parameter in config:

    framework:
        profiler:
            collect: false
    
    点赞 评论 复制链接分享
  • duanhe4267 duanhe4267 3年前

    Even late to the party, recently I had problems about Out of Memory just accessing app.php file with Symfony 3.4. Turns out that when you have SELinux set to enforcing, even if you set the permissions of var directory inside your project to 777, it won't be able to write on it. If you follow the steps in the official documentation about how deploy in production, it will return a response code 500 and write in web server's error log only that PHP has exhausted the memory limit.

    I'm no expert in SELinux, but the only way I could solve this problem was disabling SELinux, but edition /etc/selinux/config file setting SELINUX=disabled and restarting the OS.

    Again, there's reason to SELinux exists and proper configuration isn't found easily using Symfony's var sub-folders and can get hard to solve this problem without thinking of disabling SELinux.

    点赞 评论 复制链接分享
  • dstt1818 dstt1818 4年前

    I solved the Out of memory error on the Twig debug installing the XDebug.

    Because the Twig uses the PHP var_dump function internally, install the XDebug is a good idea, because it limits the var_dump() output of arrays and objects to 3 levels deep, as we can see on the documentation.

    Credits to @peezi.

    点赞 评论 复制链接分享
  • dsc80135 dsc80135 6年前

    You either disable symfony profiler (I don't think this is what you want as far as I know) or set limit to unlimited with -1 in your php.ini and restart apache.

    memory_limit = -1
    
    点赞 评论 复制链接分享
  • dqjcb132285 dqjcb132285 4年前

    If the memory limit is only being reached under the Symfony dev environment I would suggest adding the following to web/app_dev.php

    ini_set('memory_limit', '-1');
    

    This way you can continue to test the production with a sensible amount of memory. Modifying the whole environment via php.ini could hide an error down the line.

    点赞 评论 复制链接分享

为你推荐