title: PHP Program not working properly
body: <p>I have got a strange problem.This is my code:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;?php
  $fp=fopen("test.txt","w",true);
  if($fp)
  {
  $start=time();
  for($i=0;$i&lt;=17800;$i++)
  {
      fwrite($fp,"bandwith");
  }
  fclose($fp);
  $stop=time();
  $diff=round($stop-$start,2);
  $fsize=round(filesize("test.txt")/1024,2);
  $bandwidth=$fsize/$diff;
  echo "&lt;strong&gt;The speed of your broadband is&lt;/strong&gt; ".$bandwidth;
  }
  else
  {
      echo ("problem with permission");
  }
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am actually trying to calculate the bandwidth.The error I get is "Division by zero" on the $bandwidth calculation part.The strange part is that when I keep on refreshing the window I suddenly get the answer then again the problem comes during the next refresh.</p>
  
  <p>Extra info:</p>
  
  <p>I found out that the error occurs when the $start and $stop are same.Now my question is:Is localhost so damn fast to finish the text file opening and writing part within the same time resulting in division my zero error?I also checked the text file and it contains the data and it is deleted and written every other time.I just want a clear explanation of the reason behind it.</p>