php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9746 pg_close (or autoclose) closes wrong connections
Submitted: 2001-03-14 16:21 UTC Modified: 2001-03-27 10:29 UTC
From: rich at horde dot org Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 4.0.4pl1, 4.0.5-dev OS: Linux 2.2.15-2.9.0 ppc
Private report: No CVE-ID: None
 [2001-03-14 16:21 UTC] rich at horde dot org
I recall this coming up before, but I can't find it in the list of open or closed postgres bugs.

It appears as though PHP is using the arguments to pg_connect to uniquely identify connections. For example:

 $dba = pg_connect("user=foo pass=bar dbname=baz");
 $dbb = pg_connect("user=foo pass=bar dbname=baz");
 pg_close($dba);
 # $dbb is closed now too

Were one to use $dbb at this point, one would see

PHP Warning:  1 is not a valid PostgreSQL link resource in [file] at [line].

But,

 $dba = pg_connect("user=foo pass=bar dbname=baz");
 $dbb = pg_connect("pass=bar user=foo dbname=baz");
 pg_close($dba);
 # $dbb is still open

and

 $dba = pg_connect("user=foo pass=bar dbname=baz");
 $dbb = pg_connect("user=foo pass=bar dbname=baz    ");
 pg_close($dba);
 # $dbb is still open

The bug doesn't require that the handle be closed explicitly; I discovered it here where one of our programmers was having connections close when one fell out of scope.

I tried moving back to PHP 4.0.2 but the bug's there too (so it doesn't look to be a regression problem); on the other hand, a DEC Alpha running Digital Unix 4.0e and PHP 4.0.2 does *not* exhibit this behaviour.

If you're unable to duplicate it, please get in touch with me, and I'll see if I can make arrangements for a testing environment. I'll poke through the code myself for something obvious, but I'm unfamiliar with PHP internals in the first place (up to now, at least).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-14 15:37 UTC] rich at horde dot org
I tried with php4-200103141145; still as described above.


 [2001-03-14 16:38 UTC] sniper@php.net
Try latest CVS snapshot from http://snaps.php.net/
as this should be fixed.

--Jani

 [2001-03-24 13:46 UTC] romolo@php.net
Try current CVS release, at lest in my case the bug seem to be solved.
The problem appeared to be in the close function as it was closing first the specified connection and than the default one (that in the case of same connection ID are exactly the same) so that the 2nd unwilled close was really closing the connection and not just removing a ref to it.
 [2001-03-25 13:13 UTC] sniper@php.net
Reopen if problem still exists when using latest CVS.

--Jani

 [2001-03-27 10:29 UTC] rich at horde dot org
The example above no longer exhibits the problem behavior; I'll ask the user who reported the problem to me to give it a try in his (larger) application.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 11:01:30 2024 UTC