From: Colleen Williams <colleen@digital-arts.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: Persistent Connects (pg_pconnect)
Date: Tue, 28 Nov 2000 11:59:57 +0000
Message-ID: <4.3.2.7.2.20001128111923.00b3c008@192.168.1.253> (raw)
Thanks guys and gals, for your quick responses to my query about persistent
connections (you know who you are). It was much appreciated. I am posting
the results the results of our investigations in case you are interested
and also if it might help someone else...
Our investigations of the problem revealed that when using pg_pconnect on
the one Apache web server which was serving PHP pages which had many static
elements like jpgs, our postgres processes where being tied up by child web
processes which just serving lots of static elements. We had a max of 32
postgres connections while we could have up to 300 child web processes and
so problems of the CMS locking us out occurs when when we had more web
processes than postgres resources ie we had a low utilization of postgres
resources. The solution lies in having more than one web server it seems -
one to serve database type PHP pages and the other to server static
elements such as jpgs etc.
As we didn't have time to rebuild our web architecture we have used
pg_connect instead of pg_pconnect as a short term solution. It didn't
appear that much slower than when we used pg_connect.
However we had another problem, the solution with using pg_connect instead
of pg_pconnect worked on DEV but not on PROD. We think it is to do with
different PHP versions. DEV was using PHP4.0.1p2 and PROD was using
PHP4.0.3p1. We think maybe there is a variable scoping problem PHP4.0.3p1.
Perhaps PHP doesn't really work so well with object code and so we
shouldn't be using object code.
I have used the following code to do the database connect in my db.inc. To
make the code work in PROD I have had to make $connection a global variable
(by uncommenting the commented lines) as although it would connect fine and
return a valid connection index, the next time I went to fetch the query,
postgres would return an 'invalid postgres resource link' error. However in
DEV (PHP4.0.1p2) it was working fine - creating a new postgres resource
when a new query object is created.
If you can see a bug in my code and it is not at all a PHP version problem
OR if you can confirm it is a PHP version problem please let me know. I
would like to know if I am just doing it all wrong.
//global $connection;
function db_connect() {
global $DBNAME, $DBUSER, $DBPASS, $DBPORT;
//global $connection;
$connection = pg_connect("dbname=$DBNAME user=$DBUSER password=$DBPASS
port=$DBPORT ") or die("Unable to connect to server.");
return $connection;
}
//db_connect();
Class Query {
var $numrows;
var $query;
var $errormsg;
var $conn;
// constructor function
function Query() {
$this->conn = db_connect();
}
function runquery( $qstr ){
$this->query = pg_exec($this->conn, $qstr);
if ($this->query == 0) {
$this->errormsg = pg_errormessage($this->conn);
$this->numrows = 0;
}
else {
$this->numrows = pg_NumRows($this->query);
}
}
function fetchrow($ind ){
return pg_fetch_row($this->query,$ind);
}
function fetcharray($ind ){
return pg_fetch_array($this->query,$ind);
}
}
Cheers,
Colleen.
Colleen Williams
colleen@digital-arts.co.uk
0207 484 8825
Digital Arts | British Columbia House | 1 Regent Street | London | SW1Y 4NR
http://www.digital-arts.co.uk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: colleen@digital-arts.co.uk
Subject: Re: Persistent Connects (pg_pconnect)
In-Reply-To: <4.3.2.7.2.20001128111923.00b3c008@192.168.1.253>
References: <4.3.2.7.2.20001128111923.00b3c008@192.168.1.253>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox