Search code examples
phpcodeigniterout-of-memoryini-set

Codeigniter: Allowed memory size of 33554432 bytes exhausted ( already using ini_set('memory_limit', '-1'); )


On my localhost, the process in question works fine. It's basically a whole lot of number crunching.

But on my server (CentOS 5.9 + PHP 5 + MySQL 5) it gives me this error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 80 bytes) in {..}/system/database/drivers/mysql/mysql_result.php on line 147

I'm already declaring the following before running this function:

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

The system itself has 8 GB of memory. My local machine has 12 GB of memory. I doubt it needs that much memory, though.

Any insights would be greatly appreciated. Thanks in advance!


Solution

  • PHP has a global memory limit on each system where it runs that overrides your program's own memory_limit setting.

    It's the memory_limit value in a file called php.ini. Shared hosting providers often set this to something like 32M. That seems to be your problem. If you control the server you may be able to set it larger.

    Otherwise you'll need to rework your program to use less memory. (This is a very common problem when moving from development to production, sad to say.)

    Here's some advice on finding that file if you don't know where it is.

    Dude, where's my php.ini?