From: Tim Starling Date: Sun, 24 Apr 2005 07:21:15 +0000 (+0000) Subject: Automatic reconnect when the connection is lost. This hopefully won't happen much... X-Git-Tag: 1.5.0alpha1~157 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=faabce56628f8cddd781d6be9748ec55d8838430;p=lhc%2Fweb%2Fwiklou.git reconnect when the connection is lost. This hopefully won't happen much for HTTP queries, since it breaks the transaction model. But it might be useful for maintenance scripts which sleep for long periods. --- diff --git a/includes/Database.php b/includes/Database.php index 458d054407..348f18e3bc 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -306,7 +306,22 @@ class Database { # Do the query and handle errors $ret = $this->doQuery( $commentedSql ); + + # Try reconnecting if the connection was lost + if ( false === $ret && $this->lastErrno() == 2013 ) { + # Transaction is gone, like it or not + $this->mTrxLevel = 0; + wfDebug( "Connection lost, reconnecting...\n" ); + if ( $this->ping() ) { + wfDebug( "Reconnected\n" ); + $ret = $this->doQuery( $commentedSql ); + } else { + wfDebug( "Failed\n" ); + } + } + if ( false === $ret ) { + # Automatic reconnect $this->reportQueryError( $this->lastError(), $this->lastErrno(), $sql, $fname, $tempIgnore ); } @@ -1402,6 +1417,13 @@ class Database { function getServerVersion() { return mysql_get_server_info(); } + + /** + * Ping the server and try to reconnect if it there is no connection + */ + function ping() { + return mysql_ping( $this->mConn ); + } } /**