Jump to content

Lot of idle connections in MySQL


girish.kc

Recommended Posts

Hi I am using a php class to connect to the MySQL database, which uses the following code snippet.

/* establish connection, select database */
        if (0 == $this->Link_ID) 
        {
            $this->Link_ID = mysql_pconnect($Host, $User, $Password);
            if (!$this->Link_ID)
            {
                $this->halt("pconnect($Host, $User, \$Password) failed.");
                return 0;
            }
        }

        if (!@mysql_select_db($Database, $this->Link_ID))
        {
            $this->halt("cannot use database " . $this->Database);
            return 0;
        }

 

Now I'm facing the mysql idle connections problem. The number of idle connection is growing rapidly even the max_used_connection is very less.

I tried to set the variable wait_timeout and interactive_timeout to as low as 5. But there is no improvement.

 

Need some help.

 

Girish

Link to comment
https://forums.phpfreaks.com/topic/253944-lot-of-idle-connections-in-mysql/
Share on other sites

Sorry.. By mistake I posted the wrong code.

Yes I know how mysql_pconnect() works. I am not using _pconnect.. I was just testing with it.

Here is the actual code I'm using:

/* establish connection, select database */
        if (0 == $this->Link_ID)
        {
            $this->Link_ID = mysql_connect($Host, $User, $Password);
            if (!$this->Link_ID)
            {
                $this->halt("connect($Host, $User, \$Password) failed.");
                return 0;
            }
        }

        if (!@mysql_select_db($Database, $this->Link_ID))
        {
            $this->halt("cannot use database " . $this->Database);
            return 0;
        }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.