function ping() {
$ping = $this->mysqlPing();
if ( $ping ) {
+ // Connection was good or lost but reconnected...
+ // @note: mysqlnd (php 5.6+) does not support this (PHP bug 52561)
return true;
}
+ // Try a full disconnect/reconnect cycle if ping() failed
$this->closeConnection();
$this->mOpened = false;
$this->mConn = false;
public function openConnection( $i, $wiki = false ) {
if ( $wiki !== false ) {
$conn = $this->openForeignConnection( $i, $wiki );
-
- return $conn;
- }
- if ( isset( $this->mConns['local'][$i][0] ) ) {
+ } elseif ( isset( $this->mConns['local'][$i][0] ) ) {
$conn = $this->mConns['local'][$i][0];
} else {
$server = $this->mServers[$i];
}
}
+ if ( $conn && !$conn->isOpen() ) {
+ // Connection was made but later unrecoverably lost for some reason.
+ // Do not return a handle that will just throw exceptions on use,
+ // but let the calling code (e.g. getReaderIndex) try another server.
+ // See DatabaseMyslBase::ping() for how this can happen.
+ $this->mErrorConnection = $conn;
+ $conn = false;
+ }
+
return $conn;
}