salouri
salouri

Reputation: 821

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

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!

Upvotes: 4

Views: 11449

Answers (4)

Indrajeet Singh
Indrajeet Singh

Reputation: 2989

Try this code:

ini_set('memory_limit', '1024M');

Upvotes: 1

Naresh Dudhat
Naresh Dudhat

Reputation: 245

    set_time_limit(0);

    ini_set('memory_limit','2048M');

i have used set_time_limit function to handle mysql expiration time and ini_set function to handle size of data to be stored

Upvotes: 0

clod986
clod986

Reputation: 2647

Indrajeet answer worked for me.

To improve his answer, simply go to app/lib/Cake/I18N/I18N.php and in the function public function _construct() add the line

ini_set('memory_limit', '1024M');

Upvotes: 1

apurav gaur
apurav gaur

Reputation: 342

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

overrides the default PHP memory limit.

Upvotes: 3

Related Questions