#!/usr/bin/perl -w use strict; use LWP::UserAgent; use Time::HiRes qw(time sleep); my $url = $ARGV[0] || 'http://mySite.com/complexUrl.asp'; my $num_clients = $ARGV[1] || 4; my $time_between_clicks = defined($ARGV[2]) ? $ARGV[2] : 10; my $delay_between_clients = defined($ARGV[3]) ? $ARGV[3] : $time_between_clicks/$num_clients; print "\nstarting $num_clients clients at $time_between_clicks seconds between clicks\n"; print "and $delay_between_clients seconds launching delay between clients\n"; print "URL to be fetched is $url\n\n"; # autoflush on STDOUT $| = 1; for(1..$num_clients) { my $pid; if($pid = fork) { # parent $SIG{CHLD} = 'IGNORE'; sleep($delay_between_clients); } else { # child die "cannot fork :$!" unless defined $pid; my $ua = new LWP::UserAgent; $ua->agent("Flimsy Stress Tool 0.01" . $ua->agent); while(1) { my $req = new HTTP::Request POST => $url; $req->content_type('application/x-www-form-urlencoded'); #Pass request to the user agent and get a response back my $stamp = time; my $res = $ua->request($req); if($res->is_success) { # prints length page fetched and the time it took print 'LENGTH: ', length($res->content), " time: ", time - $stamp, "s\n"; } else { print "ERROR\n"; } # note that this is a Time::HiRes sleep $time_between_clicks && sleep($time_between_clicks); } } }