MySQL Connection Won't Close causing High Mem usage and crashing


Feb 3, 2013
cPanel Access Level
Website Owner
Hi all,

I'm new to the forum and thought I'd see if anyone out there would be willing to help.

We set up a new site which has about 1000 php scripts that run using about 89 fopen scripts which open multiple php scripts. We've had some server crashing issues and I think it's because the memory usage and swap gradually increase. We had sleep() in our fopen scripts and have removed that as apparently it was using up resources.

When looking at top using SSH, the mysql connection shows like this:

11292 mysql 20 0 3217m 715m 4596 S 0.7 18.7 79:51.52 mysqld

Although 18.7 is not too high right now, you can see that it's been open for almost 80 hours. How do I go about closing this process? Our webhosting technical support told us that it is probably something in our code that is keeping it open. But since we're using mysql_query($result) with a persistent connection, shouldn't it be closing automatically at the end of the script? The only thing I can think of is that the with our fopen scripts, we're not using the fclose, which should technically close out anyway no?

If anyone can provide input, I'd greatly appreciate it. This has been a HUGE headache for us and we're looking to have this resolved as soon as possible!

We have a quad core dedicated system with 4gb of ram. Each cron script takes typically no longer than 30 seconds to run.
Last edited:


Well-Known Member
Feb 4, 2006
cPanel Access Level
Root Administrator
That is not an open mysql connection, it's the mysqld (mysql server) process. 79:51:52 is "Total CPU time the task has used since it started".
see "man top".


Well-Known Member
Feb 25, 2003
In case this might help someone else, you can install mytop to get a look at the actual mysql connections and how long they have been open.