Re: [GENERAL] Perl - Apache / Postgress

From: Gilles Darold <darold(at)neptune(dot)fr>
To: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Perl - Apache / Postgress
Date: 1999-07-14 19:46:40
Message-ID: 378CE920.B8174619@neptune.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adriaan Joubert wrote:

> > Erik Colson wrote:
> >
> > I'm using Apache with mod_perl to access a PostgresSQL database (6.5)
> > .
> >
> > The script starts with connecting to the database... this means that
> > the server is actually reconnecting everytime the script starts and
> > disconnect when the HTML page is generated.

I have the same problem, I still not do something to resolve it but I
think the solution is what you
can read below :

PERSISTENT DATABASE CONNECTIONS

Another popular use of mod_perl is to take advantage of it's persistance
to maintain open database connections. The basic idea goes like so:

#Apache::Registry script
use strict;
use vars qw($dbh);

$dbh ||= SomeDbPackage->connect(...);

Since $dbh is a global variable, it will not go out of scope, keeping the
connection open for the lifetime of a server process, establishing it
during the script's first request for that
process.

It's recommended that you use one of the Apache::* database connection
wrappers. Currently for DBI users there is Apache::DBI and for Sybase
users Apache::Sybase::DBlib.
These modules hide the peculiar code example above. In addition, different
scripts may share a connection, minimizing resource consumption. Example:

#httpd.conf has
# PerlModule Apache::DBI
#DBI scripts look exactly as they do under CGI
use strict;
my $dbh = DBI->connect(...);

Although $dbh shown here will go out of scope when the script ends, the
Apache::DBI module's reference to it does not, keep the connection open.

WARNING: Do not attempt to open a persistent database connection in the
parent process (via PerlRequire or PerlModule). If you do, children will
get a copy of this handle, causing
clashes when the handle is used by two processes at the same time. Each
child must have it's own unique connection handle.

Gilles DAROLD

In response to

Browse pgsql-general by date

  From Date Subject
Next Message LOREAWMS 1999-07-14 20:02:40 subscribe
Previous Message Aaron Holtz 1999-07-14 19:26:09 Select from multiple db's