|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78982 pdo_pgsql returns dead persistent connection
Submitted: 2019-12-17 17:38 UTC Modified: -
From: kentaro at ranvis dot com Assigned:
Status: Closed Package: PDO PgSQL
PHP Version: master-Git-2019-12-17 (Git) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kentaro at ranvis dot com
New email:
PHP Version: OS:


 [2019-12-17 17:38 UTC] kentaro at ranvis dot com
PDO tells a driver to check if the connection is still alive.
For PDO PgSQL driver, this is done in pdo_pgsql_check_liveness().
It calls PQstatus() to see if the status is good,
but since PQstatus() only returns the previous status stored locally,
the driver cannot tell if the connection is actually alive.
This results in returning possible dead connection to the script.

will add a PR.

Test script:

$connArgs = ['pgsql:dbname=DB_NAME', 'USER', 'PASSWORD', [
$pdo = new PDO(...$connArgs);

var_dump($pdo->query('select 1'));
$pdo = null;

sleep(15); // kill the DB connection here
//system('sudo systemctl restart postgresql-12');
//system('net stop postgresql-x64-12 && net start postgresql-x64-12');

$pdo = new PDO(...$connArgs);
var_dump($pdo->query('select 1')); // should not throw but throws

Expected result:
outputs 1 two times

Actual result:
outputs 1 then throws an exception


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-17 17:40 UTC] kentaro at ranvis dot com
The following pull request has been associated:

Patch Name: Fix #78982: pdo_pgsql returns dead persistent connection
On GitHub:
 [2019-12-20 11:07 UTC]
Automatic comment on behalf of
Log: Fix #78982: pdo_pgsql returns dead persistent connection
 [2019-12-20 11:07 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Apr 02 13:03:41 2023 UTC