测试一个测网速的脚本,不知道哪里错了
<br />/*==创建将传输给用户的数据文件==*/ <br /><br />$fp=fopen("cs.txt","w"); <br />for($i=0;$i<1704000;$i++){ <br /> fwrite($fp,"bandwidthkh"); <br />} <br />fclose($fp);<br /><br />// ==现在编写计算网络速度的脚本=<br /><br />function microtime_float()<br />{<br /> list($usec, $sec) = explode(" ", microtime());<br /> return ((float)$usec + (float)$sec);<br />}<br />$data=file_get_contents("cs.txt");<br />$start=microtime_float(); <br />$fsize=filesize("cs.txt")/1024; // filesize返回文件大小的字节数<br />echo "向客户端发送" . $fsize . "KB数据<br>"; <br />echo "<!--" . $data . "-->"; <br />$stop=microtime_float();<br />$duration=($stop-$start);<br />echo $duration."s<br>"; <br />$speed=round($fsize/$duration,2); <br />echo "Your network speed:$speed KB/sec";<br />