in reply to Hard timeout for LWP::UserAgent or similar

What's wrong with the built-in timeout?

#! perl -slw use strict; use Time::HiRes qw[ time ]; use LWP; my $ua = LWP::UserAgent->new; $ua->timeout( 0.1 ); print time; my $response = $ua->get('http://192.168.1.31/noexist.html'); print time; if ($response->is_success) { print $response->decoded_content; # or whatever } else { die $response->status_line; } __END__ C:\test>junk76 1301504675.567 1301504675.74173 500 Can't connect to 192.168.1.31:80 (connect: timeout) at C:\test\jun +k76.pl line 17.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Hard timeout for LWP::UserAgent or similar
by camelobserver (Initiate) on Mar 30, 2011 at 17:59 UTC
    From the docs
    $ua->timeout( $secs )
    
        Get/set the timeout value in seconds. The default timeout() value is 180 seconds, i.e. 3 minutes.
    
        The requests is aborted if no activity on the connection to the server is observed for timeout seconds. This means that the time it takes for the complete transaction and the request() method to actually return might be longer.
    
    So a trickling stream of data coming in could mean the timeout never getting triggered, or getting triggered way later than timeout.
      So a trickling stream of data coming in could mean the timeout never getting triggered, or getting triggered way later than timeout.

      Remember that tcp/ip coalesces small writes into larger packets before transmission. So the slower the trickle, the longer the time between packets.

      In my simplistic testing, a 250 millisecond timeout never took longer than 315 milliseconds to actually return. If 315 is too long for you, try scaling back the value you set to say 200.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.