We are seeing lot of PHP and MYSQL Connection failure issues. It has been suggested that we shall built the retry logic, if the database connection is not successful. I have pasted below the code and the error message.
Can anybody advise what shall be the best way to implement the retry logic in this code? Any code sample which handles this?
PHP Warning: mysqli_connect(): [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connecti (trying to connect via tcp://us-cdbr-azure-west-a.cloudapp.net:3306) in D:\home\site\wwwroot\xdfdy.php on line 232
PHP Warning: mysqli_connect(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
public function connect_to_mysqldb () {
try
{
$this->conn = mysqli_connect('us-cdbr-azure-west-a.cloudapp.net','xxxxx','password', 'dbname');
}
catch (DbException $e) {
return false;
}
// Check connection
if (mysqli_connect_errno($this->conn ))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return false;
}
return true;
}