in reply to HTTP Request Wrapper Wanted

If your platform supports it (if you're Unixy, you're probably okay), you can use alarm. I'm a little concerned that the timeout appears to be failing, but could be reading your code incorrectly.

Replies are listed 'Best First'.
Re: HTTP Request Wrapper Wanted
by Anonymous Monk on Mar 06, 2003 at 14:36 UTC
    Thank you for the advise regarding alarm (I should've remembered that). Either I've implemented it incorrectly or the hanging HTTP request is also impacting the alarm because the request is still hanging and the alarm is NOT handling it as hoped. Here's the code with the alarm ..
    my $ua; my $url; my $msg; my $request; my $response; my $timeout = 50; $ua = LWP::UserAgent->new(); $ua->agent("DMC-Monitor/1.0"); $request = new HTTP::Request("GET", "$url"); print "\$request=|$request|\n"; $response = $ua->timeout($timeout); print "\$response=|$response|\n"; $msg = "Alarm Timeout!!\n"; eval { local $SIG{ALRM} = sub { die("$msg"); }; echo("alarm($timeout+2)\n"); alarm($timeout+2); # Timeout + 2 seconds. $response = $ua->request($request); # <== Hangs here alarm 0; print "\$response=|$response|\n"; }; print "$msg\n$@\n" if ($@);
    Thank you again,