本文整理匯總了PHP中Doctrine\DBAL\Connection::ping方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::ping方法的具體用法?PHP Connection::ping怎麽用?PHP Connection::ping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::ping方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getConnection
/**
* @return Connection
*/
public function getConnection()
{
if (false === $this->connection->ping()) {
$this->connection->close();
$this->connection->connect();
}
return $this->connection;
}
示例2: checkStandardConnection
/**
* @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));
}
示例3: pingIt
protected function pingIt(Connection $con)
{
if ($con->ping() === false) {
$con->close();
$con->connect();
}
return $con;
}
示例4: reconnectIfNecessary
/**
* 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();
}
}
示例5: attemptToReconnectPresumedLostConnection
/**
* 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;
}
示例6: keepalive
private function keepalive(Connection $db)
{
if (false === $db->ping()) {
$db->close();
$db->connect();
}
}