Memory leak in my PHP application (built using Codeigniter Framework)

I have a PHP application based on Codeigniter 1.7.2, currently in production and live, it seems to have a serious memory leak.

A memory leak is obvious when viewing "from above" on the server:

top - 23:42:13 up 26 days, 10:14, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 54 total, 1 running, 53 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 7872040k total, 929748k used, 6942292k free, 142464k buffers Swap: 0k total, 0k used, 0k free, 214420k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 22740 apache 15 0 308m 63m 5976 S 0 0.8 0:14.05 httpd 22733 apache 15 0 298m 54m 5968 S 0 0.7 0:13.60 httpd 22736 apache 15 0 296m 52m 5968 S 0 0.7 0:13.89 httpd 22742 apache 15 0 295m 50m 5976 S 0 0.7 0:13.05 httpd 22738 apache 15 0 294m 49m 5968 S 0 0.6 0:13.30 httpd 22744 apache 15 0 293m 48m 5968 S 0 0.6 0:13.11 httpd 

So httpd uses 0.8% * 7.9 GB of memory or about 63 MB.

I know that CI plus my application is about 7 MB in size. I know that httpd probably has some, but cannot explain 63MB, plus this number increases daily if I reboot. Thus, I came to the conclusion that there was a memory leak.

From my understanding of PHP 5.2.x, it doesn’t do “garbage collection” at all, but it frees up memory when the function exits and, finally, when the script ends. In addition, I know of several well-known constructs that can lead to a memory leak ("destruction of child objects" and recursive references to objects), but I do not do anything that you like. So I'm a little puzzled by what might be the problem.

I will try to track it using XDebug, but I will have some problems installing it on Fedora 8. If someone can point out some “normal suspects” for true memory leaks in PHP 5.2.x and / or in Code Igniter .. I hope that I’m lucky and I’ll just find the culprit if I know what to look for (I searched for search queries in CI, but didn’t smoke. I turned off the function that saved queries between functions, which helped to reduce the area, but still it seems to be leaking).

 [ root@web7 ~]# php --version PHP 5.2.6 (cli) (built: May 8 2008 08:54:23) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies [ root@web7 ~]# cat /proc/version Linux version 2.6.21.7-2.fc8xen ( mockbuild@xenbuilder4.fedora.phx.redhat.com ) (gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)) #1 SMP Fri Feb 15 12:34:28 EST 2008 
+6
php memory memory-leaks codeigniter
source share
1 answer

You tried to enable profiling in the controller:

 $this->output->enable_profiler(TRUE); 

It would be interesting to see if something appeared in the results of what shows something, it takes a little longer than usual.

In addition, you can always try CodeIgniter 2, which was released, the update is backward compatible and has many fixes.

- edit You can also try the following: I found the variable "var $ save_queries = TRUE;" on line 51 in the file / system / database / DB _driver.php

Switching to FALSE solved the problem for me.

From your controller you can use: $ this-> db-> save_queries = FALSE; Where leakage should be a problem. --edit

+2
source share

All Articles