php怎么判断用户的网络速度快慢

2025-04-03 03:09:49
推荐回答(1个)
回答1:

$fp=fopen("cs.txt","w");  
for($i=0;$i<170400;$i++){  
    fwrite($fp,"test");  
}  
fclose($fp); 


//计算网速

function getmicrotime()
    {
    list($usec,$sec) = explode("",microtime());
    return ((float)($usec) + (float)($sec));
    }
    $data = file_get_contents("cs.txt");
    $start = getmicrotime();
    $filesize = filesize("cs.txt") / 1024;
    echo "";
    $stop =   getmicrotime();
    $duration = ($stop - $start);
    $speed = round($filesize/$duration,2);
    echo "你的网速:$speed kB/秒";