/** * @return Connection */ public function getConnection() { if (false === $this->connection->ping()) { $this->connection->close(); $this->connection->connect(); } return $this->connection; }
/** * @param Connection $connection * @return Success|Failure */ private function checkStandardConnection(Connection $connection) { if ($connection->ping()) { return new Success(get_class($connection)); } return new Failure(get_class($connection)); }
protected function pingIt(Connection $con) { if ($con->ping() === false) { $con->close(); $con->connect(); } return $con; }
/** * This method checks whether the connection is still open or reconnects otherwise. * * The connection might drop in some scenarios, where the server has a configured timeout and the handling * of the result set takes longer. To prevent failures of the dumper, the connection will be opened again. */ public function reconnectIfNecessary() { if (!$this->connection->ping()) { $this->connection->close(); $this->connect(); } }
/** * It attempts to reconnect if connection is non responsive. Failing to reconnect triggers a critical error. * If connection is responsive or successfully reconnected it rethrows, relying on the bus retries * to re-execute everything from the beginning. * * @param \Exception $e * * @return \Exception|CriticalErrorException */ private function attemptToReconnectPresumedLostConnection(\Exception $e) { // presumably, any exception caught here is related to some connection error if (!$this->connection->ping()) { // if pinging fails, we try to reconnect try { $this->connection->close(); $this->connection->connect(); } catch (\Exception $e) { // if reconnecting fails, there is no way that the bus can continue to function return new CriticalErrorException("Database connection failed.", 0, $e); } } return $e; }
private function keepalive(Connection $db) { if (false === $db->ping()) { $db->close(); $db->connect(); } }