title: make PHP wait until a function completes?
body: <p>Is there any way to make PHP wait until a function returns before continuing?</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  
      set_time_limit(0);
  
      function waitforchange($nof) {
          $lfilemod=filemtime($nof);
          while(filemtime($nof) == $lfilemod) {
              clearstatcache();
              usleep(10000);
          }
      }
  
      waitforchange('./blahblah.txt')
      sleep(5);
      echo 'done';
  
  ?&gt;
  </code></pre>
  
  <p>It is supposed to wait until <code>blahblah.txt</code> changes, wait another five seconds after that, then print out "done", however, it prints out "done" after five seconds, regardless whether the file actually changed.</p>