Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Enabling timeout method in LWP::UserAgent

by dReKurCe (Scribe)
on Jul 27, 2005 at 21:25 UTC ( [id://478727]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://478727]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found