Re: Persistent Connects (pg_pconnect)

Поиск
Список
Период
Сортировка
От Colleen Williams
Тема Re: Persistent Connects (pg_pconnect)
Дата
Msg-id 4.3.2.7.2.20001128111923.00b3c008@192.168.1.253
обсуждение исходный текст
Ответ на Persistent Connects (pg_pconnect)  (Colleen Williams <colleen@digital-arts.co.uk>)
Список pgsql-sql
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=$DBNAMEuser=$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 functionfunction 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



В списке pgsql-sql по дате отправления:

Предыдущее
От: Hans-Jürgen Schönig
Дата:
Сообщение: Selecting empty columns
Следующее
От: "Gerhard Dieringer"
Дата:
Сообщение: Antw: Selecting empty columns