|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18912 pg_pconnect opens a new connection even when and old one is available
Submitted: 2002-08-15 03:03 UTC Modified: 2002-08-15 03:09 UTC
From: jc at mega-bucks dot co dot jp Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.2.2 OS: Red Hat Linux 7.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jc at mega-bucks dot co dot jp
New email:
PHP Version: OS:


 [2002-08-15 03:03 UTC] jc at mega-bucks dot co dot jp
When I use pg_pconnect() I find that sometimes PHP creates a connection even if the is alrady a currently open one.

This only happens *sometimes*. For example I reload my test code multiple times and I see no problem. However If I then load a new page, hit the back button and then re-load the test code I now see two open postgres connection where I only saw one before.

# ps -auxw | grep idle
root         3  0.0  0.0     0    0 ?        SW   13:05   0:00 [kapm-idled]
postgres  1409  0.0  0.4  6544 2208 ?        S    15:53   0:00 postgres: postgres JC [local] idle
postgres  1453  0.5  0.4  6544 2208 ?        S    15:55   0:00 postgres: postgres JC [local] idle

I use this code:


$sql = "select now()";
$res = sql_query($sql);
$dat = pg_fetch_object($res);

echo "$dat->now<br>";

function sql_query($sql) {

  //echo "$sql<br>";
  $conn = pg_pconnect("dbname=JC user=postgres");
  $res  = pg_exec($conn, $sql);

  if (!$res) {
    echo "CONNECTION: could not execute query ($sql)<br>";
  else {
    return $res;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-15 03:06 UTC]
You are probably using a multi-process web server such as Apache. Since database connections cannot be shared among different processes a new one is created if the request happen to come to a different web server child process.
 [2002-08-15 03:09 UTC] jc at mega-bucks dot co dot jp
Thanks! Could this be added to the docs then?

It has caused me quite some headaches trying to find out what was wrong with my code.

I appreciate the detailed reply, now I clearly understand why PHP was behaving the way it was.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 05:01:28 2024 UTC