title: Write and read from the same file- PHP
body: <p>I am trying to write to a file and then read the data from the same file. But sometimes I am facing this issue that the file reading process is getting started even before the file writing gets finished. How can I solve this issue ? How can i make file writing process finish before moving ahead?</p>
  
  <p>// writing to file</p>
  
  <pre><code>$string= &lt;12 kb of specific data which i need&gt;;
  $filename.="/ttc/";
  $filename.="datasave.html";
  if($fp = fopen($filename, 'w')) 
  {
      fwrite($fp, $string);
      fclose($fp);
  }
  </code></pre>
  
  <p>//    writing to the file </p>
  
  <pre><code>$handle = fopen($filename, "r")  ;
  $datatnc = fread($handle, filesize($filename));
  $datatnc = addslashes($datatnc);
  fclose($handle);
  </code></pre>