Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Are connections automatically pooled when using mod_perl?

by jdrago999 (Pilgrim)
on Dec 19, 2011 at 18:20 UTC ( #944290=note: print w/replies, xml ) Need Help??


in reply to Are connections automatically pooled when using mod_perl?

In a mod_perl environment, your variables (like database handles) can live longer than a single request if you declare them in a scope "outside" of the request.

For example:

package MyHandler; use strict; use warnings 'all'; use Apache2::RequestRec; use Apache2::RequestUtil; # Declare it here: my $persistent_thing; sub handler : method { my ($class, $r) = @_; # The first time this is executed in a child process, it will be cre +ated. # After that, you will just reuse the same one: $persistent_thing ||= make_the_thing(); } 1;

Please also check out Ima::DBI::Contextual as it solves the whole thing.

package MyDBI; use base 'Ima::DBI::Contextual'; my @dsn = ( 'DBI:mysql:dbname:hostname', 'username', 'password', { # Other options go here: RaiseError => 1, }); __PACKAGE__->set_db('Main', @dsn); 1;

Then, elsewhere:

use MyDBI; # Automatically pooled and recreated if the old one times out or dies: my $dbh = MyDBI->db_Main;

Replies are listed 'Best First'.
Re^2: Are connections automatically pooled when using mod_perl?
by Anonymous Monk on Dec 20, 2011 at 07:14 UTC
    FYI, FWIW, AFAIK, technically, neither Apache::DBI nor Ima::DBI::Contextual provide an actual pool , they merely provide a cache. The Apache::DBI docs explain this explicitly and in detail. The Ima::DBI::Contextual are more funny than informative :)

      The Ima::DBI::Contextual (docs) are more funny than informative :)

      You're right. That should probably be fixed.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://944290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2020-06-04 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?