# HG changeset patch # User Dan Fuhry # Date 1353343022 18000 # Node ID cfce82063776814dc9beb686d2fa78158d5fff69 # Parent b19698a37d58479e865d69b208ff53449190d859 DBAL: Persistent connections; also explicitly commit and unlock tables when shutting down diff -r b19698a37d58 -r cfce82063776 includes/dbal.php --- a/includes/dbal.php Mon Nov 19 11:36:37 2012 -0500 +++ b/includes/dbal.php Mon Nov 19 11:37:02 2012 -0500 @@ -208,7 +208,19 @@ $host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}"; - $this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd); + // Try a peristent connection twice + // http://us2.php.net/manual/en/function.mysql-pconnect.php#99380 + $this->_conn = @mysql_pconnect($host_line, $dbuser, $dbpasswd); + if ( !@mysql_query("SELECT 1;", $this->_conn) ) + { + $this->_conn = @mysql_pconnect($host_line, $dbuser, $dbpasswd); + if ( !@mysql_query("SELECT 1;", $this->_conn) ) + { + // if that doesn't work, use a normal connection + $this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd); + trigger_error(E_USER_WARNING, "Forced to use nonpersistent mysql connection"); + } + } unset($dbuser); unset($dbpasswd); // Security @@ -536,6 +548,9 @@ function close() { + // anything we locked should certainly be unlocked now; + @mysql_query("COMMIT;", $this->_conn); + @mysql_query("UNLOCK TABLES;", $this->_conn); @mysql_close($this->_conn); unset($this->_conn); }