网络测速 php代码

时间:2024-01-29 07:57:43
<?php  
/*=====http://hi.csdn.net/yinyiniao=====*/  
$fp=fopen("cs.txt","w");  
for($i=0;$i<170400;$i++){  
    fwrite($fp,"bandwidth");  
}  
fclose($fp);  
/*=====http://hi.csdn.net/yinyiniao=====*/  
?>  
<?php  
/*=====http://hi.csdn.net/yinyiniao=====*/  
function mymicrotime(){  
    list($usec, $sec) = explode(" ",microtime());  
    return ((float)$usec + (float)$sec);  
}  
$data=file_get_contents("cs.txt");  
$start=mymicrotime();  
$fsize=filesize("cs.txt")/1024;  
//echo $fsize."kb<br>";  
echo "<!--".$data."-->";  
  
$stop=mymicrotime();  
$duration=($stop-$start);  
//echo $duration."s<br>";  
$speed=round($fsize/$duration,2);  
echo "Your network speed:$speed KB/sec";  
  
  
?> 

 

 

转自:https://blog.csdn.net/yinyiniao/article/details/4935445