perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xinhuan Zheng <xzh...@christianbook.com>
Subject Re: Apache::DBI connect
Date Fri, 08 Nov 2013 19:58:28 GMT
Hi Perrin,

The query is from the application code not the 'select 1' test query.

While most of time I saw Apache::DBI->connect is called but sometime from a process, it
will print out it finds a cached connection and ping is ok but sometimes from the same process
it didn't find a cached connection. Since it's the same process, it doesn't make sense it
can find a cached one then it didn't find any. Even after it says it didn't find a cached
one then after that it prints out it still has a cached one and can use that one. It sounds
like in same process sometimes the Apache:DBI connection cache can be accessed but sometimes
it cannot.

The base class is similar to a class in Java world. Basically it has set and get methods.
Among other things, it sets $db and gets $db. The class has its own fetch method and it'll
use $self->db method call to do the fetch/insert,etc. BTW, the class has a method AUTOLOAD,
although I don't quite understand how AUTOLOAD works. The document says the method call will
be magically come to exist with AUTOLOAD. If this is not desirable, then should we get rid
of $db completely from the base class?  Then every time it needs fetch/insert,etc, call DBI->connect_cached
instead since that way Apache::DBI->connect will be called and the connection can be validated?

- xinhuan

From: Perrin Harkins <pharkins@gmail.com<mailto:pharkins@gmail.com>>
Date: Friday, November 8, 2013 10:41 AM
To: Xinhuan Zheng <xzheng@christianbook.com<mailto:xzheng@christianbook.com>>
Cc: Adam Prime <adam.prime@utoronto.ca<mailto:adam.prime@utoronto.ca>>, "modperl@perl.apache.org<mailto:modperl@perl.apache.org>"
<modperl@perl.apache.org<mailto:modperl@perl.apache.org>>
Subject: Re: Apache::DBI connect


On Thu, Nov 7, 2013 at 11:06 PM, Xinhuan Zheng <xzheng@christianbook.com<mailto:xzheng@christianbook.com>>
wrote:
As I turned on more debugging, when the problem occurs, the Apache cached connection reference
is different than the database handle reference the query is using.

Which query are you talking about?  The ping in Apache::DBI?  Or something else in your own
code?

We use Apache::DBI and DBI and use Apache::DBI is before DBI. We actually call DBI->connect_cached
and based on DBI document, I guess this would be handled by Apache::DBI connect.

Yes, it should be.

However, I guess we also defined a base class that can store a database handle. There are
subclasses inherited from this base class. Is that good idea to store a database handle in
a base class?

No, don't do that.  You should pick one approach for managing database handles, whether it's
Apache::DBI or something else, and only use that.  If you keep a database handle around in
a global somewhere, it may time out and nothing will ping it because you're not calling connect()
on each request.

- Perrin

Mime
View raw message