Re: passing resource id's through functions - Mailing list pgsql-php

From Andrew McMillan
Subject Re: passing resource id's through functions
Date
Msg-id 1010808121.27734.56.camel@kant.mcmillan.net.nz
Whole thread Raw
In response to passing resource id's through functions  (Chadwick Rolfs <cmr@shell.gis.net>)
Responses Re: passing resource id's through functions  (Chadwick Rolfs <cmr@shell.gis.net>)
List pgsql-php
On Sat, 2002-01-12 at 04:44, Chadwick Rolfs wrote:
> I seem to have figured out that pg_connect returns a resource ID that will
> not pass into another function, and that pg_pconnect does.  I'm not too
> keen on the persistent connections.  Can someone confirm this belief?  I'm
> trying to remember where on php.net I read how to pass pg_connect
> resources to other functions, and haven't found it at functions,
> persistent connections, pg_connect or pg_pconnect.
>
> Any help would be appreciated, and helpful :)

I run all my calls to pg_Exec inside a wrapper function which logs the
query to syslog if it fails for some reason, or if it takes unreasonably
long to execute (this has been a great aid to debugging and performance
improvement).  This means that _every_ time I want to execute a query I
am passing the appropriate database connection into my wrapper function.

I don't see any difference here between using pg_connect vs. pg_pconnect
for connecting to the database, other than performance.  I have recently
started to migrate back from pg_pconnect to pg_connect because I can get
the same performance without the resource overhead now that I use
DBBalancer to provide connection pooling.

It might be that I don't see any difference because connecting to the
database(s) is something I do globally, rather than inside a function,
or through instantiating an object.

If you use persistent connections, Apache has a "MaxRequestsPerChild"
setting, after which the Apache client process will exit, closing any
PHP persistent PostgreSQL connections as well.  The trouble is, that
setting this to an arbitrarily low number will reduce the benefit from
persistent connections in the first place, setting it arbitrarily high
can cause a problem if your application tickles any memory leaks in
Apache or PHP.

Cheers,
                    Andrew.
--
--------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/        PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201    MOB: +64(21)635-694    OFFICE: +64(4)499-2267
       Are you enrolled at http://schoolreunions.co.nz/ yet?


pgsql-php by date:

Previous
From: Frank Bax
Date:
Subject: Re: passing resource id's through functions
Next
From: "Culley Harrelson"
Date:
Subject: Re: passing resource id's through functions