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 ~]