Suspended MySQL connections issue

Installing and configuring Tera-WURFL on your server.

Suspended MySQL connections issue

Postby dryabov » Thu Sep 09, 2010 8:03 am

We use TeraWURFL in our project MobileJoomla (mobilejoomla.com), and recently we have got request with max_user_connections issue (http://www.mobilejoomla.com/forum/topic.html?id=470). IMHO this issue is because of TeraWURFL doesn't close MySQLi connection. Actually, I always thought that PHP should close all the opened mysql connection at the end of script work, but it seems that it doesn't work in some cases. Comment at php.net suggests this assumption: http://www.php.net/manual/en/mysqli.close.php#97521 (but call mysqli::kill seems needless here).

The idea is to add destructor for TeraWurfl with something like
Code: Select all
   // Destructor
   public function __destruct(){
      if(is_object($this->db))
         $this->db->close();
   }

and implement close method in each of TeraWurflDatabase classes. E.g., for MySQLi this method will look like
Code: Select all
   public function close(){
      if($this->connected === true)
         $this->dbcon->close();
   }
Last edited by dryabov on Sun Sep 12, 2010 6:04 am, edited 1 time in total.
dryabov
 
Posts: 4
Joined: Thu Sep 09, 2010 7:37 am

Re: Suspended MySQL connections issue

Postby kamermans » Thu Sep 09, 2010 1:25 pm

Interesting. I have noticed this error when doing regression testing where over 60,000 user agents are tested as fast as possible.

I'll definitely include the destructor in version 2.1.3 (to be released soon). As far as MySQL::kill() is concerned, there are conflicting comments, one poster says "You should always use mysqli_kill() function before mysqli_close() to actually close and free up the tcp socket" while another (under MySQL::kill) says "Be careful using this before mysqli::close. Killing the thread before actually closing the connection will leave the connection open". As you suggested, I will not use the kill() method.

For users with PHP >= 5.3.0, Tera-WURFL will default to a persistent MySQLi connection, the connection will be reused.

I think I'll put the destructor on the DB Connector as opposed to the TeraWurfl class, but I'm not quite sure yet...
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: Suspended MySQL connections issue

Postby dryabov » Sun Sep 12, 2010 6:53 am

kamermans wrote:I think I'll put the destructor on the DB Connector as opposed to the TeraWurfl class, but I'm not quite sure yet...

Yes, you right, it's better place for disconnecting (actually, my logic was that if TeraWURFL initiates connection, it should finalize also; but your way looks more compact and clear).
dryabov
 
Posts: 4
Joined: Thu Sep 09, 2010 7:37 am

Re: Suspended MySQL connections issue

Postby kamermans » Sun Sep 12, 2010 10:33 am

Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX


Return to Installation / Configuration

Who is online

Users browsing this forum: No registered users and 3 guests

cron