1
我正在轉換一些Perl代碼使用LWP :: UserAgent :: DNS ::主機到PHP。php curl url ip地址綁定
perl代碼正在做的是對負載平衡池中的多個單獨服務器進行頁面加載時間測量。由於服務器使用基於名稱的虛擬主機,Perl代碼使用該行更改URL /主機名到IP綁定:
LWP::UserAgent::DNS::Hosts->register_host(
'www.mytesturl.com' => '22.22.22.22',
);
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
#actually enforces new DNS settings as if they were in /etc/hosts
LWP::UserAgent::DNS::Hosts->enable_override;
$Timerstart=[gettimeofday];
my $response= $ua->get('http://www.mytesturl.com');
$TimeElapsed = tv_interval ($Timerstart,[gettimeofday]);
if ($response->is_success) {
print "<br>Response detected - Time to Load: $TimeElapsed seconds\r\n"
}
我知道我可以用原始套接字操作做到這一點,但我希望我能用cURL或PHP中的其他類庫來實現。 perl代碼實際上在一個循環內部重複執行這個循環,對於同一個url(每個ip是一個特定的服務器)使用幾個不同的IP來單獨測試服務器。
Thanks-