PDO constructor very slow (mysql)
-
10-07-2019 - |
Question
This bit of code is taking almost a half second to execute. Could somebody help me with some reasons this could be happening and some possible solutions?
If it matters, the DB is hosted by amazon rds
$this->_connection = new PDO(
$dsn,
$this->_config['username'],
$this->_config['password'],
$this->_config['driver_options']
);
Solution
PDO's constructor opens a database connection. When the DB is on a remote server, a half second (500ms) pause isn't too surprising, given ping times and the fact that you're not just opening a connection, but also logging in to it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow