|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75419 Database connection not garbage collected
Submitted: 2017-10-23 15:10 UTC Modified: 2017-10-23 18:47 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: abedi at xento dot com Assigned: pollita (profile)
Status: Closed Package: PostgreSQL related
PHP Version: 7.1.10 OS: Ubuntu 16/Windows 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: abedi at xento dot com
New email:
PHP Version: OS:


 [2017-10-23 15:10 UTC] abedi at xento dot com
Multiple database connections opened via pg_connect are not being garage collected & closed. 

Test script:

$dbLink1 = pg_connect( "host=localhost port=5432 dbname=development", PGSQL_CONNECT_FORCE_NEW );
pg_query($dbLink1, 'select 1; /*FIRST*/');

$dbLink2 = pg_connect( "host=localhost port=5432 dbname=development", PGSQL_CONNECT_FORCE_NEW );
pg_query($dbLink2, 'select 1; /*SECOND*/');

/*closing first link*/

$dbLink2 = pg_connect( "host=localhost port=5432 dbname=development", PGSQL_CONNECT_FORCE_NEW );
pg_query($dbLink2, 'select 1; /*THIRD*/');

/*2nd 3rd connection remain idle on the database connection as long as the scripts is alive, the 2nd connection overridden by $dbLink2 should be automatically destroyed*/



Expected result:
Only one connection referenced by $dbLink2 should be open on the database. The problem doesn't appear on earlier versions of php 5, works fine in php 5.5, 5.6 and the database correctly reports only 1 connection idle

Actual result:
2 open idle connections reported on the database on any PHP 7.X version, 

#1. idle connection for the query of select 1; /*SECOND*/
#2. idle connection for the query of select 1; /*THIRD*/


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-23 18:10 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pollita
 [2017-10-23 18:10 UTC]
I can see what happened and should have a fix soon.
Basically, every extension needed to be touched for the PHP 7 API changes and some logic got flipped in PGSQL's "default link" handling.
 [2017-10-23 18:47 UTC]
-Status: Assigned +Status: Closed
 [2017-10-23 18:47 UTC]
Applied to PHP-7.0, PHP-7.1, PHP-7.2, and master.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Oct 03 00:03:42 2022 UTC