vancetech has asked for the wisdom of the Perl Monks concerning the following question:
How would you go about setting up a foolproof daemon with a constant mysql server connection?my $dbh; RECONNECT: eval { my $dsn = "DBI:$driver:database=$database;host=$hostname;mysql_con +nect_timeout=10"; $dbh = DBI->connect($dsn, $username, $password, { RaiseError => 1, + PrintError => 0, AutoCommit => 1 }); }; if( $@ ) { goto RECONNECT; } eval { # Setup ALRM handler signal local $SIG{ALRM} = sub { die "timeout\n" }; alarm( 60 ); $dbh->do("INSERT INTO table_name VALUES ( data, ... )"); alarm( 0 ); }; if( $@ ) { if( $@ =~ /timeout/ ) { print "Timed out\n"; } else { alarm( 0 ); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl daemon with persistant mysql connection problems
by jesuashok (Curate) on Apr 03, 2006 at 09:30 UTC |