php脚本ab压测获得数据

<?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;
}
?>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值