hello wise men !

hope you can answer my question...

I've a perl web-application running on mod_perl2.0.4 and Apache 2.2.10.
In the http.conf this entry is - for sure - commented out:
#PerlModule Apache::DBI

If i use the /server-info page from apache it's showing me the loaded modules:

mod_perl.c, mod_setenvif.c, mod_rewrite.c, mod_negotiation.c, mod_mime.c, mod_log_config.c, mod_isapi.c, mod_info.c, mod_include.c, mod_expires.c, mod_env.c, mod_dir.c, mod_cgi.c, mod_autoindex.c, mod_authz_user.c, mod_authz_host.c, mod_authz_groupfile.c, mod_authz_default.c, mod_authn_file.c, mod_authn_default.c, mod_auth_basic.c, mod_asis.c, mod_alias.c, mod_actions.c, mod_so.c, http_core.c, mpm_winnt.c, mod_win32.c, core.c

so, again no Apache::DBI.

Now the interesting part:

I open a database connection in my appliaction like this: $dbh = DBI->connect_cached($dsn, $db_user_name, $db_password, {AutoCommit => 0, PrintError => 0, PrintWarn => 0}) or die $DBI::errstr;

$dbh is a global variable which is used in other modules.


I am not issuing a $dbh-> disconnect.
I don't know why i should do that

So i would guess now, that the database-connection is closed after every request - but it's not, which a can tell from the mysql logs.


So here is the code:


# global database-handlers
our $dbh;
our $dbh_sessions;

sub checkDbh {
if (defined($dbh)) {
if ($dbh->ping == 1) {
# ok
}
else {
initDbh();
}
}
else {
initDbh();
}
}




sub initDbh {
undef($dbh);
my $dsn="DBI:mysql:travel:localhost";
my $db_user_name = $travelproject::props->getProperty('db_user');;
my $db_password = $travelproject::props->getProperty('db_password');;
eval { $travelproject::log->info("establishing db-connection(application)...");
$travelproject::log->info("dsn: $dsn");
$travelproject::log->info("db_user: $db_user_name");
$dbh = DBI->connect($dsn, $db_user_name, $db_password, {AutoCommit => 0, PrintError => 0, PrintWarn => 0}) or die $DBI::errstr;
};
if ($@) {
my $error = $@;
$travelproject::log->error($error);
$travelproject::log->error("Database connection not made: $DBI::errstr");
undef($dbh);
return;
}
else {
$travelproject::log->info("successfully connected to database");
}
# check if autocommit is really disabled
if ($dbh->{'AutoCommit'}) {
my $error = "unable to turn of autocommit";
$travelproject::log->error($error);
undef($dbh);
return;
}
}


# for every new request coming in i call:
checkDbhs();

-------------------------------------------------
This database-handle seems to stay there forever,
when i don't call ->disconnect on it.
So any clue why i have a persistant connection even though i am not using Apache::DBI ?

I am confused now...
Can you help me ?

In reply to persistent database connection without Apache::DBI by hoggle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.