gbguccku has asked for the wisdom of the Perl Monks concerning the following question:

i have a script for a school project so the timeout i set 1 second and it stay alot of time i don't know why :(

use strict; use diagnostics; use warnings; use LWP::UserAgent; use HTTP::Request; use HTTP::Response; my $def = new LWP::UserAgent; my $hostsfile; my $host; my @hosts; my $userresp; my $url; my @checks = ("http://HOST:5555/server/test.php"); my $ua = LWP::UserAgent->new(agent => "School", env_proxy => 1, keep_a +live => 1,timeout => 1); print qq(Host File Name:\t); $hostsfile = <STDIN>; chomp($hostsfile); open(IN, $hostsfile) or die "$!"; @hosts = <IN>; chomp(@hosts); print qq(School A28A group B project\n); print qq(Output Saved To CGIVTI.log.\n\n); foreach $host (@hosts) { foreach (@checks) { $url = $_; $url =~ s/HOST/$host/; #$url = $_; print qq(:: Checking $url...\n); my $request = new HTTP::Request('GET', $url); my $response = $def->request($request); if ($response->is_success) { print $response->content; open(OUT, ">>CGIVTI.log"); print OUT $url; close OUT; } else { print qq(Not wOKING..\n\n); } } } <>

look the timeout is 1 second and it stays 3-4 mins or more . Please help me. Thanks Cox.

I put all the code

Replies are listed 'Best First'.
Re: Hello i have a problem with timeout in my script
by kennethk (Abbot) on Mar 08, 2015 at 18:48 UTC
    Welcome to the monastery. As Happy-the-monk was alluding to, the script you have posted should run in less than a second, since you are not actually connecting to anything. Please post a complete example - something that when you run requires 3-4 minutes - so that we can run the exact code you run. This is particularly important, since the default timeout on LWP::UserAgent is 180 seconds, which would put the script at the 3-4 minute range. See How do I post a question effectively? for more details.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: Hello i have a problem with timeout in my script
by Happy-the-monk (Canon) on Mar 08, 2015 at 16:31 UTC

    Above code as it is at the time I am seeing it is not actually doing it.

    I take it, the part of it connecting to some website (maybe one stored in @checks?) should be there but is not.

    If that really was all there is, it should finish instantaneously.

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

Re: Hello i have a problem with timeout in my script
by Anonymous Monk on Mar 08, 2015 at 23:27 UTC
    LWP timeout option is IO::Socket timeout option, meaning time between packets received, not total time elapsed