Elliott has asked for the wisdom of the Perl Monks concerning the following question:

Dear Brethren, I am using LWP::Simple to GET a remote URL. I complained to our webhosts about our server hanging from time to time and they complained right back at me! Oops. It turns out that my own script is frequently hanging. My guess is that this happens when the script tries to GET a URL and the remote server fails to respond.

Has anyone got a better guess?

More importantly can anyone tell me how to prevent this happening - perhaps by exiting the script after waiting a few seconds for a response?

Replies are listed 'Best First'.
Re: LWP::Simple hanging (maybe?)
by aukjan (Friar) on Aug 10, 2005 at 11:25 UTC
    If you want to control timeouts, I think that LWP::Simple is just that.. too simple. If you want finer control over your "GET's", use LWP::UserAgent instead. This provides a 'timeout' method which you can use to timeout sooner.
    --
    Go Fish!

      ++ and for example

      #!/usr/bin/perl -w use strict; use LWP::UserAgent; my $agt = LWP::UserAgent->new(); $agt->timeout( 10 ); my $res = $agt->get( 'http://www.perlmonks.org' ); if( $res->is_success ) { print " ... ok\n"; } else { print " ... failed: ", $res->code, "\n"; }

      -derby