我使用Google Cloud SQL第二代实例和使用PHP PDO驱动程序的持久连接,但有时,在某些App Engine实例中,池化连接损坏,连接开始失败,发送给用户的一条丑陋的信息。
我试图解决这个问题,试图建立新的连接,甚至禁用持久性,但它没有工作:
for ($attempt = 1; !$this->link; $attempt++) {
try {
if ($attempt > $persistent / 2) {
unset($options[PDO::ATTR_PERSISTENT]);
}
$this->link = new PDO($dsn_string, $user, $pass, $options);
} catch (PDOException $err) {
if ($attempt <= $persistent) {
usleep($attempt * 100000);
} else {
throw new DB_Exception("Error connecting database (after $attempt attempts):\n" . $err->getMessage(), $err->getCode(), null, $err);
}
}
}