Forum Moderators: coopster

Message Too Old, No Replies

Memory leak

How to find memory leak in php script

         

painless

4:47 am on May 15, 2006 (gmt 0)

10+ Year Member



I believe the script i'm using on my site is leaking badly. I host the site on a vps and using 'top' on 10 minutes interval shows that i'm losing memory about 10k a minute. The script uses many string functions, several regular expression and lots of array manipulation.

My question is. How do find the leak in that script? Is anyone got a checklist to discover a memory leak or about what functions that usually cause a memory leak. This problem is really makes me frustated. My temporary solution is to restart the httpd every five minutes using cron. If i hadn't done this the server would broke twice a day. Tried searching google for this but can't find any useful information.

Please help

jatar_k

3:16 pm on May 15, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the first place to start I think would be to unset anything that is unused as you go through the script

are you sure it is that script only?

painless

12:07 am on May 16, 2006 (gmt 0)

10+ Year Member



Yes, i'm sure. Since that is the main script of the site. I already tried unsetting everything ( arrays, strings, objects ) whenever i'm through with them but still the leak won't go away. Is there any guidelines on common programming procedures that could lead to memory leak? Or some functions that i should avoid because they have reputation of causing a memory leak?

coopster

12:09 am on May 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Which version of PHP are you running and on which OS? Is there any database activity going on?

painless

3:42 am on May 16, 2006 (gmt 0)

10+ Year Member



I'm using PHP 4.4.1 on a vps running on fedora. There are some mysql activities. Using top -n1 i found these :

20196 mysql 16 0 31204 11m 3760 S 0.0 0.4 0:00.22 mysqld
20216 mysql 16 0 31204 11m 3760 S 0.0 0.4 0:00.26 mysqld
20217 mysql 20 0 31204 11m 3760 S 0.0 0.4 0:00.00 mysqld
20219 mysql 16 0 31204 11m 3760 S 0.0 0.4 0:00.00 mysqld
20221 mysql 16 0 31204 11m 3760 S 0.0 0.4 0:00.00 mysqld
20222 mysql 20 0 31204 11m 3760 S 0.0 0.4 0:00.00 mysqld
20263 mysql 16 0 31204 11m 3760 S 0.0 0.4 0:01.66 mysqld
20265 mysql 16 0 31204 11m 3760 S 0.0 0.4 0:01.29 mysqld
20266 mysql 16 0 31204 11m 3760 S 0.0 0.4 0:00.00 mysqld
20268 mysql 15 0 31204 11m 3760 S 0.0 0.4 0:00.51 mysqld

Are they the one causing the problem?

coopster

2:28 pm on May 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Only you can determine that. If you don't need the database running then shut it down and see if your problem persists.