|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
43 - 18 = ?
Subscribe to this entry?

 [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: Thu May 23 21:01:31 2024 UTC