I've just opened submitted a bug relating to postgres database connections not been closed/cleaned by the garbage collector in any php 7.X version for the below scenario, I was hoping if someone could provide some insight on why such a behavior & point any .ini settings that could help avoid this.
<?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); ?>
On PHP 5.6, 5.5 I'm noticing all unused connections are automatically cleaned up and I'm left with just 1 idle connection on the database, which doesn't seem to be the case in PHP 7.