#18912 [Bgs]: pg_pconnect opens a new connection even when and old one is available
| From: | jc at mega-bucks dot co dot jp | Date: | Thu, 15 Aug 2002 07:09:32 +0000 |
| Subject: | #18912 [Bgs]: pg_pconnect opens a new connection even when and old one is available | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16886@lists.php.net to get a copy of this message | ||
ID: 18912
User updated by: jc@mega-bucks.co.jp
Reported By: jc@mega-bucks.co.jp
Status: Bogus
Bug Type: PostgreSQL related
Operating System: Red Hat Linux 7.2
PHP Version: 4.2.2
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2002-08-15 03:06:23] 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:03:10] jc@mega-bucks.co.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;
}
}
?>
~
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18912&edit=1