Leser: 27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl use warnings; use strict; use LWP::Online 'online'; my $start = time(); my $now = time() - $start; my $conn = 0; while (1) { if ( online('http') ) { $conn = 1; last; } sleep(1); $now = time() - $start; if ($now > 30) { print "30 seconds over. No connection. Aborting.\n"; last; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/perl use warnings; use strict; use LWP::Online 'online'; my $start = time(); my $now = 0; my $max = 30; my $conn = 0; while ($now < $max) { if ( online('http') ) { $conn = 1; last; } sleep(1); $now = time() - $start; } die "$max seconds over. No connection. Aborting.\n" unless $conn;
return '' if $bad > 2;
1
2
3
4
5
6
7
8
9
@RELIABLE_HTTP = (
# These are some initial trivial checks.
# The regex are case-sensitive to at least
# deal with the "couldn't get site.com case".
'http://google.com/' => sub { /About Google/ },
'http://yahoo.com/' => sub { /Yahoo!/ },
'http://amazon.com/' => sub { /Amazon/ and /Cart/ },
'http://cnn.com/' => sub { /CNN/ },
);
1 2 3 4 5 6 7 8
my $count = 0; unless ( online('http') && $count < 30) { sleep(1); $count++; }
1 2 3 4 5 6 7 8 9 10
while (! online('http') && $count < 30) { sleep 1; $count++; } # Schleife wurde beendet; sind wir jetzt Online oder nicht? # Alternativ hier auf den Wert von $count testen, dann wird der # Online-Test nicht noch mal ausgeführt. unless ( online('http') ) { die "bäh, nicht online...\n"; }