I just found out that some of my LWP programs have (inadvertantly) caused a DOS attack on a web site over the last few days. :( The site's netstat command returns a long list of (addresses changed):
tcp 1 0 ::ffff:1.2.3.4:80 ::ffff: 5.6.7.8:33196 CLOSE_WAIT 27647/httpd
Some questions: Does this reuse a connection or keep opening new connections?
#!/usr/bin/perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new(agent => "", timeout => 30); my $response; my $url = 'http://example.com/'; while () { sleep 60; $response = $ua->get($url); if (not ($response->is_success)) { print "Can't retrieve page: " . $response->status_line . "\n"; next; } my $page = $response->content; [... process content] }
If it does, a second (similar) program seems like the culprit. I can run it up to twenty times in five minutes, usually with three or four retrievals per instance. The program takes just a few seconds, and then exits completely, but apparently without telling the server to close the connection Does some way exist to close the connection when I exit the program? The second program:
#!/usr/bin/perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new(agent => "", timeout => 30); my $url = 'http://example.com/index.php?do=action'; [... some parameter checking] for my $i (@ARGV[2..$#ARGV]) { my $response = $ua->post($url, [ value0 => $ARGV[0], value1 => $ARGV[1], value2 => $i, Submit => 'Submit' ] ); if (not ($response->is_success)) { die "Can't retrieve page: " . $response->status_line . "\n"; + } my $page = $response->content; [... process content] }
I will usually start getting: Can't retrieve page: 500 read timeout errors after a while (while an ordinary browser will continue to access the site without problems). Thank you very much in advance for your suggestions.

In reply to Closing the connection by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.