I do not use Symfony, but I used Doctrine\DBAL\DriverManager::getConnection() .
I had to take the DriverManager step and make this song and dance to indicate the connection timeout ( ATTR_TIMEOUT ):
function buildDbConn($config, $timeout) { $params = $config->toArray(); $params['driverOptions'] = [ PDO::ATTR_TIMEOUT => intval($timeout), PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]; $driver = new Doctrine\DBAL\Driver\PDOMySql\Driver; return new Doctrine\DBAL\Connection($params, $driver); }
I always need the pdo_mysql driver, this can be customized.
source share