php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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:

<?php

$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>";
    die;
  }
  else {
    return $res;
  }
}
?>
~



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-15 03:06 UTC] edink@php.net
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: Sat Dec 21 14:01:32 2024 UTC