Re: best practie for open and close connection database

Michael Peters <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
On 04/21/2010 12:33 PM, Felipe de Jesús Molina Bravo wrote:

> In my application, I opened my database from authentication handler and
> close it from child exit handler. It is correct (is a best practice)? or
> is a bad design?

Typically it's best practice to not close DB handles. That's why 
Apache::DBI is such a popular module since it handles all of connection 
caching for you.

With some databases (I'm looking at you Oracle) it's expensive to create 
a new database connection so it's more important. With others (like 
MySQL) it's really cheap so there's not a big penalty for not caching.

There are some cases where caching connections is actually a bad thing: 
If you have too many application servers where each has a connection to 
your database and thus overwhelms your database with too many 
connections even though the actual load isn't overloading. But most 
people in this situation will use a proxy like DBD::Gofer to manage the 
DB connections.

-- 
Michael Peters
Plus Three, LP
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.