DBD-mysql - mysql_auto_reconnect problems

Posted on Wed Jul 20 16:54:01 2005 by jspath
mysql_auto_reconnect problems

I am using mysql_auto_reconnect to ensure that my long running process can reliably interact with mysql. Here is the code I use to execute statements and account for auto reconnects.

my $rc = $sth->execute(@$bind); if (!$rc) { if ($dbh->errstr && $dbh->errstr =~ /(?:lost connection|mysql server has gone away)/i) { $rc = $sth->execute(@$bind); if (!$rc) { return; } else { return 1; } } else { return; } } else { return 1; }

I've tested this functionality by establishing the connection, then killing the database process, then attempting to execute a statement. The first execute fails as expected, with a "lost connection" error, and DBD::mysql automatically reestablishes the connection so that the 2nd execute will work.

The problem is, when I leave it for long periods, the first execute fails, AND the 2nd execute fails, both with the "MySQL server has gone away." error message. mysql_auto_reconnect does not seem to have an effect in this case.

I don't understand the point of mysql_auto_reconnect if it doesn't reconnect in the "server has gone away" case.

Direct Responses: 766 | Write a response