📄 mysql.pm
字号:
use DBI;sub PerformCheck($$) { my $timeout = shift; my $host = shift; # get connection info my $peer = $config->{host}->{$host}; if (ref($peer) ne 'HASH') { return "ERROR: Invalid host!"; } my $host = $peer->{ip}; my $port = $peer->{port}; my $user = $peer->{user}; my $pass = $peer->{password}; my $res = eval { local $SIG{ALRM} = sub { die "TIMEOUT"; }; alarm($timeout); # connect to server my $dsn = "DBI:mysql:host=$host;port=$port;mysql_connect_timeout=$timeout"; my $dbh = DBI->connect($dsn, $user, $pass, { PrintError => 0 }); unless ($dbh) { alarm(0); return "ERROR: Connect error (host = $host:$port, user = $user, pass = '$pass')! " . DBI::errstr; } # Check server (simple) my $sth = $dbh->prepare("SELECT NOW()"); my $res = $sth->execute; unless($res) { alarm(0); return "ERROR: SQL Query Error: " . $dbh->errstr; } $sth->finish; $dbh->disconnect(); $dbh = undef; alarm(0); return 0; }; alarm(0); return $res if ($res); return 'ERROR: Timeout' if ($@ =~ /^TIMEOUT/); return "UNKNOWN: Error occurred: $@" if $@; return "OK";}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -