The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Workarounds and Optimization' started by smohzie, Feb 3, 2013.

  1. smohzie

    smohzie Registered

    Joined:
    Feb 3, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
    #1 smohzie, Feb 3, 2013
    Last edited: Feb 3, 2013
  2. quietFinn

    quietFinn Well-Known Member

    Joined:
    Feb 4, 2006
    Messages:
    998
    Likes Received:
    10
    Trophy Points:
    18
    Location:
    Finland
    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".
     
  3. STS Admin

    STS Admin Well-Known Member

    Joined:
    Jul 8, 2012
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Edit php.ini and set the mysql.allow_persistent value to off
     
  4. DavidR

    DavidR Well-Known Member

    Joined:
    Feb 25, 2003
    Messages:
    177
    Likes Received:
    0
    Trophy Points:
    16
    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.
     
Loading...

Share This Page