CakePHP: Allowed memory size exhausted, increasing memory_limit is not helping

salouri picture salouri · Jul 21, 2014 · Viewed 9.8k times · Source

Specs = CakePHP 2.4.6, PHP 5.3.13, Windows 7 x64, Apache Server 2.4.9.

I keep getting this error:

Allowed memory size xxxx exhausted

I have tried everything I could find, increasing memory_limit or max_execution_time inisde php.ini file is not helping no matter how much I increase the limits. My Apache server has openssl enabled (some say it might be related), php_pdo_mysql is enabled too. I am using fastCGI for PHP and it's not helping to switch to php5_module!

The strange thing is that it was working on my localhost for a while and not working on the dev server, and recently it's not working on my localhost as well (I started getting execution time error instead sometimes)

Here is the action I am using:

public function index() {

    $this->Certificate->recursive = 0; 
    $certificates = $this->Certificate->find('all',         
        array(       
        'conditions' => array('course_id !=' => '1'),       
        'contain' => array(

                         'CertificateStatus.status',
                         'Course.title',
                         'Student.full_name',
                         'User.name'

                 )));
    $this->set(compact('certificates'));
}

Any ideas as to what could be the reason for this problem? how would I find memory leaks in CakePHP? What could be the solution to fix/optimize it?

** New Update:

After limiting the number of "fields" in the find(), and after increasing some Fcgid numbers inside httpd, now I can fetch the whole table, but it takes 5 minutes for the page to load completely, which is a failure performance wise!

Is this related to CakePHP caching? If yes, is there any way to optimize it for this number of records?? Everyone tells me that 26,000 text records is not a "huge" data set!

Answer

apurav gaur picture apurav gaur · Jul 22, 2014
ini_set('memory_limit', '-1'); 

overrides the default PHP memory limit.