<?php
$ipv4Addr = "www.baidu.com";
$ipv6Addr = "ipv6.baidu.com";
if (!strcmp($argv[1], "ipv4"))
{
$httpAddr = $ipv4Addr;
}
elseif (!strcmp($argv[1], "ipv6"))
{
$httpAddr = $ipv6Addr;
}
else
{
$httpAddr = "";
echo "error: ".$argv[1]."\n";
}
if(!empty($httpAddr))
{
$allData = getData($httpAddr);
$fileHandle = fopen($argv[1]."Data.txt","w");
fwrite($fileHandle, $allData);
fclose($fileHandle);
}
function getData($httpAddr)
{
$rowData = "";
for($concurrentNumber = 100; $concurrentNumber <= 100; $concurrentNumber++)
{
$rowData = $rowData.$concurrentNumber;
$outPut = getResult($concurrentNumber, $httpAddr);
print_r($outPut);
preg_match("/\d+\.\d+/", $outPut[20], $match);
$tunTuLv = $match[0];
$rowData = $rowData.",".$tunTuLv;
preg_match("/\d+\.\d+/", $outPut[21], $match);
$QingQiuDengDai = $match[0];
$rowData = $rowData.",".$QingQiuDengDai;
preg_match("/\d+\.\d+/", $outPut[22], $match);
$WanChengQingQiu = $match[0];
$rowData = $rowData.",".$WanChengQingQiu;
preg_match("/\d+\.\d+/", $outPut[23], $match);
$WangLuoChuanShu = $match[0];
$rowData = $rowData.",".$WangLuoChuanShu;
preg_match_all("/\d+/", $outPut[27], $match);
$connectMean = $match[0][1];
$rowData = $rowData.",".$connectMean;
preg_match_all("/\d+/", $outPut[28], $match);
$processMean = $match[0][1];
$rowData = $rowData.",".$processMean;
preg_match_all("/\d+/", $outPut[29], $match);
$waitMean = $match[0][1];
$rowData = $rowData.",".$waitMean;
preg_match_all("/\d+/", $outPut[30], $match);
$totalMean = $match[0][1];
$rowData = $rowData.",".$totalMean;
preg_match_all("/\d+/", $outPut[37], $match);
$percentageTime = $match[0][1];
$rowData = $rowData.",".$percentageTime."\n";
echo $rowData;
}
return $rowData;
}
function getResult($concurrentNumber, $httpAddr)
{
exec("ab -n 10000 -c ".$concurrentNumber." ".$httpAddr, $outPut, $returnVar);
return $outPut;
}
?>