Skip to content

Commit 7763fce

Browse files
authored
Fixed bug that connect_timeout cannot work for pgsql-swoole database. (#7402)
1 parent 3f648e7 commit 7763fce

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Connectors/PostgresSqlSwooleExtConnector.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ public function createConnection(array $config): PostgreSQL
4848
{
4949
$connection = new PostgreSQL();
5050

51-
$result = $connection->connect(sprintf(
51+
$conn = sprintf(
5252
'host=%s port=%s dbname=%s user=%s password=%s',
5353
$config['host'],
5454
$config['port'],
5555
$config['database'],
5656
$config['username'],
5757
$config['password']
58-
));
58+
);
59+
60+
if (isset($config['pool']['connect_timeout'])) {
61+
$result = $connection->connect($conn, $config['pool']['connect_timeout']);
62+
} else {
63+
$result = $connection->connect($conn);
64+
}
5965

6066
if ($result === false) {
6167
throw new Exception($connection->error ?? 'Create connection failed, Please check the database configuration.');

0 commit comments

Comments
 (0)