网络测速 php代码

<?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

posted @ 2018-08-30 20:40  Z_Chan  阅读(1683)  评论(0编辑  收藏  举报