in reply to disconnect, then ping returns true under apache, false from command line, no Apache::DBI around. Why would this be?

AFAIK mod_perl tries to keep db connections alive and reuse them as much as possible. See http://perl.apache.org/docs/1.0/guide/databases.html#Introduction for some details.
It may be possible that you're actually using Apache::DBI without being aware of it, perhaps check your httpd.conf?
  • Comment on Re: disconnect, then ping returns true under apache, false from command line, no Apache::DBI around. Why would this be?

Replies are listed 'Best First'.
Re^2: disconnect, then ping returns true under apache, false from command line, no Apache::DBI around. Why would this be?
by msouth (Sexton) on Mar 30, 2006 at 15:40 UTC
    Thanks for the advice.

    The complete httpd.conf is included in my question--I reduced it to the nine lines or so in an attempt to eliminate that question.

    I also grepped keys %INC for Apache and found nothing in there in the script--is that sufficient to be sure that Apache::DBI is not the culprit?

    I am working on DBI->trace output now to see if I get any clues out of that output.

    One interesting thing is that I replaced the code with one that explicitly undefs the $dbh, and that seemed to disconnect ok (which would probably be a sufficient workaround). But when I put it in an if branch so I could set a variable to decide whether to try undef()ing or disconnect()ing, both undef() and disconnect() appeared to work.

    I am currently trying to figure out if that is really what is happening, I will post here with results.

    Thanks again for your input.

      The DBI->trace output showed me that mysql_auto_reconnect was on when the script was run by Apache.

      Note that this is true even if you don't have Apache::DBI (which completely overloads disconnect), and even if you don't have mod_perl. DBD::mysql checks for MOD_PERL or GATEWAY_INTERFACE in the env, and if it sees them, turns on mysql_auto_reconnect on the handle when you connect. (perldoc DBD::mysql for details.)

      So in my case I needed to explicitly set  $dbh->{mysql_auto_reconnect} = 0 and then call $dbh->disconnect. Otherwise, when I "verify that it's disconnected" with the ping() call, I actually reconnect first. (The ping() was really just something I was doing to make sure that Apache::DBI hadn't snuck itself back in--a debugging device.)

      Thanks again for help everyone.

      Oh, also, in comparing two DBI->trace outputs I wrote a hack to help diff ignore the differences in memory addresses. Here it is:

      #!perl -w #use like this, if file1 and file2 are two traces of similar db operat +ions: # perl ox2read <file1 >file1scrub # perl ox2read <file2 >file2scrub # diff -c file1scrub file2scrub >mydiff use strict; my @seen_addy = (); while (my $line = <>) { foreach my $sr ( @seen_addy ) { my $search = $sr->[0]; my $replace = $sr->[1]; $line =~ s/$search/$replace/g; } while ($line =~ /(0x\w+)/) { my $search = $1; my $last_replace = @seen_addy ? $seen_addy[$#seen_addy]->[1] : + 'addy001'; my $replace = ++$last_replace; push @seen_addy, [$search, $replace]; $line =~ s/$search/$replace/g; } print $line; }
      It's possible that you are seeing MySQL's auto-reconnect feature. See the DBD::mysql docs for more info on how to disable this.
Re^2: disconnect, then ping returns true under apache, false from command line, no Apache::DBI around. Why would this be?
by derby (Abbot) on Mar 30, 2006 at 15:15 UTC

    ++ but also check your startup.pl

    -derby