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,
|