0

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.

Akash
  • 4,956
  • 11
  • 42
  • 70

1 Answers1

0

This is a confirmed bug in PHP7 and shall be fixed in a future release.

Details: https://bugs.php.net/bug.php?id=75419

Fix Commit: https://github.com/php/php-src/commit/a645af44561acb4696bc9b98a656781ded81fb79

Akash
  • 4,956
  • 11
  • 42
  • 70