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

能不能通过用户访问php文件,判断用户网络速度.

阅读 3.5k
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 "<!--".$data."-->";
    $stop =   getmicrotime();
    $duration = ($stop - $start);
    $speed = round($filesize/$duration,2);
    echo "你的网速:$speed kB/秒";
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题