Home > Backend Development > PHP Tutorial > 测试一个测网速的脚本,不知道错哪了

测试一个测网速的脚本,不知道错哪了

WBOY
Release: 2016-06-13 12:25:07
Original
1374 people have browsed it

测试一个测网速的脚本,不知道哪里错了

<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 />
Copy after login

结果测出的结果是

达到1g每秒,这不可能啊?
------解决思路----------------------
以前我用ajax做上传文件时,几G的文件几秒就传好了,所以我觉得用本地的电脑既当服务器又当客户端,这个速度是正常的
------解决思路----------------------

引用:
以前我用ajax做上传文件时,几G的文件几秒就传好了,所以我觉得用本地的电脑既当服务器又当客户端,这个速度是正常的
这样的话,你能说是网速吗?不要自欺欺人了
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template