收到一个接收get请求的压力测试的需求,
require LWP::UserAgent;##LWP是perl的http请求模块
use strict;
use POSIX qw(strftime);##输出时间
use threads; ##threads~~~
my $addr = "http://192.168.244.128/";
my @threads;
    
sub   getDRqureyURL()   
my ($l,$DRqureyURL,$phoneNumber)=@_;##获取所有参数
my$ua= LWP::UserAgent->new;
$ua->timeout(1);##设置timeout时间,通常是10+,这里是测试
$ua->env_proxy;##获得环境变量
my$response=$ua->get($DRqureyURL);##get
if($response->is_success){
print$response->decoded_content;# or whatever :P
}
else{
die$response->status_line;
}
print $l.' '.$phoneNumber.' '.strftime("%Y-%m-%d %H:%M:%S\n", localtime(time));
}
my $j; 
my $i;
open (TEST,"phonenumber.txt");
my $line ;
for ($j = 0;$j < 2;$j++)
{
$i=0;
while($i<20)   
{
$line = <TEST>;
    if (!$line)
    {
print "end of file, reopen.";##最后一行为空
open (TEST,"phonenumber.txt");
$line = <TEST>;
}
chop($line );##排除换行符
$threads[$i]  =   threads->new(\&getDRqureyURL,   $i,   $addr,   $line);  
$i++;
}
foreach my $thread (@threads) {
$thread->join();##回收thread
}
}
close (TEST);##关闭test句柄