Re: help with perl please?
Posted in 2008
On Fri, Dec 19, 2008 at 10:50 AM, Norma Jean Sebastian <nsebastian@flinnsci.com> wrote: > I know this isn't really the forum for this, but I am hoping some kind soul > who knows perl can help me. > > I am very new to perl, actually so new that I am simply trying to hack a > script I inherited. > > The script has statements as follows (url was changed): > > my $useragent = LWP::UserAgent->new( protocols_allowed => ["https"] ); > > my $request = POST( "https://xxxxx/xxxx.dll", $request_values ); > > my $response = $useragent->request( $request ); So, you've found the LWP::UserAgent documentation at http://search.cpan.org/~gaas/libwww-perl-5.822/lib/LWP/UserAgent.pm It notes that the default timeout is 180 seconds. It says that the construct (new) can be used like: $ua = LWP::UserAgent->new( %options ); So all that we need is to ensure you get a hash passed across. This example code shows that you are doing that correctly: #!/bin/perl -w use strict; sub x { my(%hash) = @_; foreach my $key (sort keys %hash) { print "$key => $hash{$key}\\n"; } } x(abc => '123', def => 321, bcd => 'binary-coded decimal'); Further down the manual page, it says: $ua->timeout $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, you should be able to find out what the timeout is after you've created the user agent, as well as set it as you create the user agent. One possibility that I wouldn't rule out is "there is no way to reduce the timeout below 3 minutes". It depends on what contributes to the timeout. > I have found that when there is an internet issue, it takes 3 minutes for > the script to timeout. I found (google) this can be changed by setting a > timeout value in the UserAgent. So I tried both of the following, but it's > not making a difference, I still timeout in 3 minutes instead of 10 seconds: > > attempt #1: > > my $useragent = LWP::UserAgent->new( protocols_allowed => ["https"] ); > $useragent->timeout(10); > > Attempt #2: > > my $useragent = LWP::UserAgent->new( protocols_allowed => ["https"], > timeout => 10, > ); printf "New timeout: %d\\n", $useragent->timeout; That's a check...what you've done looks correct. Which version of LWP::UserAgent are you using? print "$LWP::UserAgent::VERSION\\n"; Which version of Perl are you using? Which platform? -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/ "Blessed are we who can laugh at ourselves, for we shall never cease to be amused." NB: Please do not use this email for correspondence. I don't necessarily read it every week, even.