时间:2021-07-01 10:21:17 帮助过:45人阅读
/*==创建将传输给用户的数据文件==*/
$fp=fopen("cs.txt","w");
for($i=0;$i<1704000;$i++){
fwrite($fp,"bandwidthkh");
}
fclose($fp);
// ==现在编写计算网络速度的脚本=
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$data=file_get_contents("cs.txt");
$start=microtime_float();
$fsize=filesize("cs.txt")/1024; // filesize返回文件大小的字节数
echo "向客户端发送" . $fsize . "KB数据
";
echo "";
$stop=microtime_float();
$duration=($stop-$start);
echo $duration."s
";
$speed=round($fsize/$duration,2);
echo "Your network speed:$speed KB/sec";