Re: [GENERAL] Perl - Apache / Postgress

Поиск
Список
Период
Сортировка
От Gilles Darold
Тема Re: [GENERAL] Perl - Apache / Postgress
Дата
Msg-id 378CE920.B8174619@neptune.fr
обсуждение исходный текст
Ответ на Perl - Apache / Postgress  ("Erik Colson" <beaver@glo.be>)
Список 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


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

Предыдущее
От: Aaron Holtz
Дата:
Сообщение: Select from multiple db's
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: [GENERAL] Select from multiple db's