PHP Fatal error: Allowed memory size exhausted

Anything special in this module? Is it processing huge amount of data? Using non-standard PHP extensions? Reading huge files? Doing recursive calls?

the module wasn’t anything special. just a contact form with a few simple pages.

the error occurred the first time I clicked the contact form’s link to open the module, pointing to the YiiBase::autoload method and it didn’t happen again after reloading the webpage

so i thought maybe something was wrong with my server’s cache! now I reinstalled the zend server, disabled all the extra extensions, and reduced the memory_limit to 32MB hoping the error occurs more often and I can debug it

no errors since then yet :)

I know this thread is a few months old now but I just experienced this as well on my local dev and thought I should share my findings.

After adding the following code to one of my models

    private $filetmp_path='protected/artworkImages/tmp/';

    private $file_path='protected/artworkImages/';

    public function __construct()



        $this->filetmp_path = $this->filetmp_path . date('Y-m');

        $this->file_path = $this->file_path . date('Y-m');


I started getting the following error

Fatal error: Allowed memory size of 131072000 bytes exhausted (tried to allocate 523800 bytes) in /var/www/someproject/protected/models/Artwork.php on line 378 

It’s interesting that there isn’t 378 lines in the file so I don’t know what to make of it. Simply removing the construct removes the problem.

change from __construct() to init()

[color="#006400"]/* Moved from Bugs to General Discussion */[/color]

I have had similar issues in the past, and they were all due to valid requirements. Adjusting the memory limits in PHP worked well.

I am now presented with a new scenario, where I am producing dynamically a large output (sitemap xml file), which exceeds any reasonable memory limit I would ever set in PHP.

The question here is how to get around Yii’s output rendering and buffering mechanisms so that I can just flush the content out rather than keeping it in memory?


To get around the buffering, I suppose that emptying the output buffers is sufficient (as now done in the EExcelView extension):


 * Performs cleaning on mutliple levels.


 * From le_top @



private static function cleanOutput()







Yii logger leaks memory. My console application was performing a loop of a couple of millions AR requests. Logger was consuming all my memory. Disabling it solved the issue.

If you were logging the AR requests, then the logger was keeping all those messages in memory because they are dumped at the end of the application. If it is that, it is not a o leak. It could be a memory leak if the logger would be allocating memory and not free it when it does not need this memory anymore.

I did not log anything in my console application. I just saved some AR’s.

I had this error on YII2 when I tried to run my project in debug mode on production server. I just commented out specified lines, as it described in index.php:

// comment out the following two lines when deployed to production

//defined('YII_DEBUG') or define('YII_DEBUG', true);

//defined('YII_ENV') or define('YII_ENV', 'dev');