3

I have a problem disabling validation of the connection in Apache::DBI.
From the perldoc:

Apache::DBI->setPingTimeOut($data_source, $timeout)

This configures the usage of the ping method, to validate a connection. Setting the timeout to 0 will always validate the database connection using the ping method (default). Setting the timeout < 0 will de-activate the validation of the database handle.

I tried calling setPingTimeOut with the same $data_source as in connect() but it didn't work. Did anyone manage to disable the pings?

planetp
  • 14,248
  • 20
  • 86
  • 160
  • can you post your $data_source? (With anything secret suitably obfuscated.) – martin clayton Dec 16 '10 at 14:28
  • @martin: I connect using this dsn: `DBI:mysql:database=dbname;host=localhost`. I tried this one with $timeout = -1 but to no avail. I also tried `dbi:mysql:dbname` – planetp Dec 16 '10 at 14:32
  • 1
    in the code it looks like only dsn matching regexp /dbi:\w+:.*/ will register ping timeouts successfully. Your second dsn looks plausible. Note the comment "use a DSN without attribute settings specified within" for the setPingTimeOut function. – martin clayton Dec 16 '10 at 14:45
  • @martin: It seems like this regex match causes the problem. After I changed dsn to `dbi:mysql:database=dbname;host=localhost` it works. – planetp Dec 16 '10 at 14:56

1 Answers1

4

To clarify, the code has:

# use a DSN without attribute settings specified within !
sub setPingTimeOut {
    my $class       = shift;
    my $data_source = shift;
    my $timeout     = shift;

    # sanity check
    if ($data_source =~ /dbi:\w+:.*/ and $timeout =~ /\-*\d+/) {
        $PingTimeOut{$data_source} = $timeout;
    }
}

Note the 'sanity check'. Hence ping timeout for a data source name with uppercase 'DBI:' will be silently ignored.

martin clayton
  • 76,436
  • 32
  • 213
  • 198