In our Laravel 5.2 application, we have an AWS database setup using multiple read servers (and multiple database connections).
At night, we changed the DNS resolvers for all web servers to Google DNS (8.8.8.8 and 8.8.4.4). Then the servers started to spit:
PDOException: "PDOException" exception with the message " SQLSTATE [HY000] [2002] php_network_getaddresses: getaddrinfo failed: name or service is not known " in /home/forge/studydrive.net/releases/20170320162143/vendor/laravel/framework/src/ Illuminate / Database / Connectors / Connector.php: 55
The code in Connector.php:55 is just a PDO constructor:
public function createConnection($dsn, array $config, array $options) { $username = Arr::get($config, 'username'); $password = Arr::get($config, 'password'); try { $pdo = new PDO($dsn, $username, $password, $options); // <== THIS ONE } catch (Exception $e) { $pdo = $this->tryAgainIfCausedByLostConnection( $e, $dsn, $username, $password, $options ); } return $pdo; }
.Env configuration for AWS (with change of sensitive parts):
DB_HOST=myapp-cluster.cluster-123abc.eu-west-2.rds.amazonaws.com DB_HOST_WRITE=myapp-cluster.cluster-123abc.eu-west-2.rds.amazonaws.com DB_HOST_READ=myapp-cluster.cluster-ro-123abc.eu-west-2.rds.amazonaws.com
So it seems like PHP PDO suddenly cannot resolve the name DB_HOST .
Please note that we cannot use IP for DB_HOST , since the host name (from the AWS side) is mapped to 3 different database READ servers.
Also, before we changed the decision, everything worked fine.
Does anyone know what might cause a PDO error or how to solve it?
php mysql amazon-web-services dns laravel
lesssugar
source share