php.net |  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
Votes:1
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
 [2017-10-23 15:10 UTC] abedi at xento dot com
Description:
------------
Multiple database connections opened via pg_connect are not being garage collected & closed. 

Test script:
---------------
<?php

$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*/
pg_close($dbLink1);

$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*/

sleep(200); 

?>

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*/

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-23 18:10 UTC] pollita@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: pollita
 [2017-10-23 18:10 UTC] pollita@php.net
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] pollita@php.net
-Status: Assigned +Status: Closed
 [2017-10-23 18:47 UTC] pollita@php.net
Applied https://github.com/php/php-src/commit/a645af44561acb4696bc9b98a656781ded81fb79 to PHP-7.0, PHP-7.1, PHP-7.2, and master.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC