Reviving a thread 4 months later...

On 5/10/06, Perrin Harkins <[EMAIL PROTECTED]> wrote:
On Wed, 2006-05-10 at 10:26 -0700, Jay Buffington wrote:
> At first I was caching the database handle myself when running outside
> of mod_perl.  In mod_perl I was relying on Apache::DBI returning the
> same handle every time I called connect().  That didn't work.

What didn't work about it?  If you use the same parameters, you should
always get the same handle.

Ohhh, I misunderstood. It's not a pool of pools.  "Practical mod_perl"
refers to a 'pool' of connections
(http://modperlbook.org/html/ch20_01.html#pmodperl-CHP-20-SECT-1).  I
took this to mean that it maintains several connections for each
connection string, but after reading through the Apache::DBI source I
see that the pool he is referring to is the different connection
strings.

But, that handle might have expired, so it is possible to get a
different handle.  I'm worried that it's not safe to do this:

use Apache::DBI;
use DBI;

my $dbh = DBI->connect(...);
$dbh->do("insert values('foo') into bar');

# time passes... and then:

my $new_dbh = DBI->connect(...);
$new_dbh->commit();

Since transactions are handle specific and there is no guarantee that
I'm going to get the exact same handle, I'm scared my insert might not
get committed.

Of course, I might just be whining about a corner case that never
exists in real life.  If the handle is active when I do the insert,
it's probably going to be active when I do the commit moments later.

> I considered allocating a handle in the pnotes() at the beginning of
> every request using a PerlInitHandler, but that is expensive,
> especially since many requests don't even use a handle.

Are the requests that don't need a database running mod_perl code?  If
not, they should be served by a proxy.

Good point.  Static requests are served from a squid cache a light
weight web server (Perlbal).

Thanks,
Jay

Reply via email to