From faabce56628f8cddd781d6be9748ec55d8838430 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 24 Apr 2005 07:21:15 +0000 Subject: [PATCH] Automatic 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. --- includes/Database.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 ); + } } /** -- 2.20.1