in reply to Re^3: Ignoring/Trapping the DIE signal
in thread Ignoring/Trapping the DIE signal
Anyway, I just went digging through my old code to find an example of what I'd used. Basically, I used a very simplified version of the above - something like this:
sub check_db_connection { return 0 if $db->ping; for my $try (1 .. 3) { sleep 15; Log(*LOGFILE, "WARNING:: $0::db appears to have gone away, att +empting to reconnect (try $try)"); return 0 if $db = connectdb('mydatabase'); } Log(*LOGFILE, "ERROR: $0:Cannot reconnect to mydatabase, exiting." +); close(*LOGFILE); exit 0; }
Then what I did was call check_db_connection before each database transaction.
Is this the best way to do it? (I doubt it)
Are there potential traps with the above? (Probably)
But.... it worked fine for me for several months :)
Cheers,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Ignoring/Trapping the DIE signal
by chrism01 (Friar) on Jun 15, 2006 at 23:45 UTC |