return (string)$this->mConn;
}
+ /**
+ * Make sure that copies do not share the same client binding handle
+ * @throws DBConnectionError
+ */
+ public function __clone() {
+ $this->connLogger->debug(
+ "Cloning " . get_class( $this ) . " is not recomended; forking connection:\n" .
+ ( new RuntimeException() )->getTraceAsString()
+ );
+
+ if ( $this->isOpen() ) {
+ // Open a new connection resource without messing with the old one
+ $this->mOpened = false;
+ $this->mConn = false;
+ $this->mTrxLevel = 0; // no trx anymore
+ $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname );
+ $this->lastPing = microtime( true );
+ }
+ }
+
/**
* Called by serialize. Throw an exception when DB connection is serialized.
* This causes problems on some database engines because the connection is
}
/**
- * Run a few simple sanity checks
+ * Run a few simple sanity checks and close dangling connections
*/
public function __destruct() {
if ( $this->mTrxLevel && $this->mTrxDoneWrites ) {
$fnames = implode( ', ', $danglingWriters );
trigger_error( "DB transaction writes or callbacks still pending ($fnames)." );
}
+
+ if ( $this->mConn ) {
+ // Avoid connection leaks for sanity
+ $this->closeConnection();
+ $this->mConn = false;
+ $this->mOpened = false;
+ }
}
}