in reply to How do I tell if a remote site is up?

Either ping it (using something like Net::Ping), or create a timeout wrapper around LWP:
local $SIG{ALRM} = sub { die }; eval { alarm(10); # LWP request alarm(0); };
-s.

Replies are listed 'Best First'.
Re: Re: How do I tell if a remote site is up?
by Elliott (Pilgrim) on Nov 11, 2003 at 18:21 UTC
    Sounds great - now what am I doing wrong?

    #!/usr/bin/perl use LWP::Simple; print "Content-type: text/html\n\n<html><body bgcolor=white>\n"; local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required eval { alarm 4; $content = get("http://select.worldpay.com/wcc/info?op=rates&instI +d=36128"); alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors # timed out print "timed out<BR>"; } else { # didn't print "succeeded<BR>"; } if($content) { print $content; } else { print "Durrr"; }

    It's still hanging.

    I haven't really understood how to use SIGALARM - I am just coding-by-numbers at the moment hoping that understanding will dawn.

      Ah.. I've tried it on a different server and it works perfectly. I wonder what the difference is.