本文整理汇总了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();
}
}