|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80546 Persistent connections appear open despite being closed
Submitted: 2020-12-22 21:17 UTC Modified: 2021-06-09 14:09 UTC
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jeremys at ha dot com Assigned:
Status: Open Package: PDO DBlib
PHP Version: 7.3.25 OS: RHEL 7.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
48 - 14 = ?
Subscribe to this entry?

 [2020-12-22 21:17 UTC] jeremys at ha dot com
Because PHP_DBLIB doesn't implement pdo_dbh_check_liveness_func (its value is null, which is "equivalent to returning SUCCESS"), when instantiating a new PDO object using persistent connections with dblib, if the connection dies, PHP is not aware of it and any subsequent queries using the connection fail with "DBPROCESS is dead or not enabled".

pdo_dbh_check_liveness_func definition:

pdo_dblib's implementation:

In this specific example, a Microsoft SQL Server is used to simulate a connection timeout using the WAITFOR DELAY query (which causes the connection to be considered dead by dblib). Connection is made using FreeTDS 1.1.x.

Based on the source, seems to be an issue in PHP 8 as well.

Test script:
for( $i = 0; $i <= 1; $i++ )
    $pdo = new PDO( 'dblib:dbname=northwinds;host=contoso', 'username', 'password', [
        PDO::ATTR_PERSISTENT => false,
        PDO::ATTR_TIMEOUT    => 5
    ] );
        if( $i == 0 )
            $pdo->query( "WAITFOR DELAY '00:00:10'" );
        var_dump( $pdo->query( "SELECT 'output' AS Output" )->fetch( PDO::FETCH_ASSOC )['Output'] );
    catch( Throwable $e )
        var_dump( stripos( $pdo->errorInfo()[2], 'DBPROCESS is dead or not enabled' ) === 0 );
    $pdo = null;

Expected result:
string(6) "output"

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-23 15:57 UTC] jeremys at ha dot com
Total copy/paste error on my part, PDO::ATTR_PERSISTENT should be set to true in the test script.
 [2021-06-09 14:09 UTC]
Right, if check_liveness is (properly) implemented by the driver,
all is good.  This is basically the same issue as bug #64603
(which is about PDO_Firebird).

However, apparently PDO doesn't require drivers to implement that
method, so I wonder whether the respective code for persistent
connections[1] shouldn't be generally changed:

    if (!pdbh->methods->check_liveness || FAILURE == (pdbh->methods->check_liveness)(pdbh)) {

In words, if check_liveness is not implemented, assume the
connection to be dead.

[1] <>
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Sep 29 11:05:53 2022 UTC