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


Greetings

I am attempting to use the timeout function of LWP::UserAgent. The following code is straight from the documentation yet I can not successfully utilize the timeout. I am attempting to access an unreachable address, and if nothing is returned within a set amount of time (less than the default of three minutes), I would like the process to stop attempting to reach (what will be ovbiously) an unreachable host.

Guidence would be appreciated

#! /usr/bin/perl use Crypt::SSLeay; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $response = $ua->get('https://66.11.78.112'); #this timeout statement is not effective $ua->timeout(3); if ($response->is_success) { print $response->content; # or whatever } else { die printf " %s\n", $response->status_line; }

Replies are listed 'Best First'.
Re: Enabling timeout method in LWP::UserAgent
by marto (Cardinal) on Jul 27, 2005 at 22:02 UTC
    Hi,

    Try setting the timeout before making the request:
    #!/usr/bin/perl use Crypt::SSLeay; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(3); my $response = $ua->get('https://66.11.78.112'); #.... and so on
    The above code is untested btw.
    hope this helps,

    Martin
      Marto: Thanks for the quick reply but this change does not produce a succesful early timeout.
        Strange,

        Im not getting the 3 minute timeout your still experiencing with the above code.

        Martin
        UPDATE:
        Grettings monks, the difficulty ecountered with this call to timeout appears to be related to https. Thanks all.