title: PHP - Wait for file to exist
body: <p>I wanted to exec a exe which generates txt files and also in another script then check that the txt files have been created. </p>
  
  <p>In xampp i am simply dragging in a test.txt file to the following php scripts dir but it doesn't seem to work correctly, also if i add in text.txt to the dir and start the script rather than starting before it is added then the second echo never seems to happen.</p>
  
  <p>How can i make PHP Wait for the text file to exist and then continue?</p>
  
  <pre><code>set_time_limit(0);
  
  echo "Script began: " . date("d-m-Y h:i:s") . "&lt;br&gt;";
  
  $status = file_exists("test.txt");
  while($status != true) {
      if ($status == true) {
          echo "The file was found: " . date("d-m-Y h:i:s") . "&lt;br&gt;";
          break;
      }
  }
  </code></pre>
  
  <p>This also does not work:</p>
  
  <pre><code>set_time_limit(0);
  
  echo "Script began: " . date("d-m-Y h:i:s") . "&lt;br&gt;";
  
  while(!file_exists("test.txt")) {
      if (file_exists("test.txt")) {
          echo "The file was found: " . date("d-m-Y h:i:s") . "&lt;br&gt;";
          break;
      }
  }
  </code></pre>