On Wed, Jun 26, 2002 at 02:19:56PM -0700, Michael A Chase wrote:
> On Wed, 26 Jun 2002 21:42:55 +0100 Rory Campbell-Lange <[EMAIL PROTECTED]> 
>wrote:
> 
> > I have a script which I imagine will loop every 15 to 60 seconds.
> > 
> > Should I make the database connection at the beginning of the script,
> > and just keep reusing it, or would it be more prudent to remake the
> > connection in the body of the loop?
> > 
> > I'm connecting to postgresql on localhost (Linux).
> 
> Much more efficient to keep the connection.  You will want to be sure to
> check for failures caused by losing the connection and either quit or
> recover somehow.

Yeap. Something like:

        while (...) {

                eval {

                        $dbh = DBI->connect_cached(..., { RaiseError => 1 });

                        ... do the work here ...

                }

        }

Note the connect_cached.

Tim.

Reply via email to