title: how to swap the content of two files in PHP
body: <p>I want to swap the content of two files using php. but it seems that the file executions are processed on the end of the script and in a strange way. because it always either write the content into only one file or nothing happens, but the files were rewritten.</p>
  
  <p>i tried the following:</p>
  
  <pre><code>rename($file1,$file2_temp);
  rename($file2,$file1); // replace the file1
  rename($file2_temp,$file2); // save the temporary file2 as the file2
  </code></pre>
  
  <p>i also tried to put it into <code>fopen</code> and <code>flock</code> statements, but it didnt work.</p>
  
  <p>does anyone have a solution for that?</p>