<?php
 $fh=fopen("textfile.txt",'w');
 for($x=0;$x<170400;$x++)
  fwrite($fh,"bandwidth");
fclose($fh);
?><?php
 $data=file_get_contents("textfile.txt");
 $fsize=filesize('textfile.txt')/1024;
$start=time();
echo "<!-- $data -->";
$stop=time();
$duration=$stop-$start;
$speed=round($fsize/$duration,2);
echo "Your network speed :$speed KB/sec.";
?>当执行代码,警告 分母为0.
这是为什么,这段代码是那个""PHP与MYSQL......"

解决方案 »

  1.   

    $start=time();
    echo "<!-- $data -->";
    $stop=time();因为$data很小所以 $start=$stop
      

  2.   

    用microtime();
    <?php
     $data=file_get_contents("textfile.txt");
     $fsize=filesize('textfile.txt')/1024;
    $start=microtime(true);
    echo "<!-- $data -->";
    $stop=microtime(true);
    $duration=$stop-$start;
    $speed=round($fsize/$duration,2);
    //$speed = 10;
    echo "Your network speed :$speed KB/s.";
    ?>
      

  3.   

    谢谢楼上各位,我3M的网测速是20000KB/S,正常吗?