title: PHP while(true) loop for file updates
body: <p>I've got the following problem at hand:</p>
  
  <p>I'm having users on two seperate pages, but saving page input to the same text file. While one user is editing, the other can't. I'm keeping track of this with sessions and writing changes and who's turn to edit it is in a file. </p>
  
  <p>Works fine so far, the output in the end is quite similar to a chat. However, right now I'm having users manually actualize their page and reload the file. What I'd like to do is have the page execute a redirect when the file-timestamp changes (to indicate that the last user has saved their edits and its another users turn). I've looked into javascript shortpolling a little, but then found the php filmtime function and it looks much easier to use. Well - here's what I got:</p>
  
  <pre><code>while(true){
     $oldtimestamp=filemtime(msks/$session['user']['kampfnr'].txt);
     $waittimer=2;
     $waittimer++;
     sleep($waittimer);
     $newtimestamp=filemtime(msks/$session['user']['kampfnr'].txt);
  
     if ($eintragszeit2 &gt; $eintragszeit1){
         addnav("","kampf_ms.php?op=akt");
         redirect("kampf_ms.php?op=akt");
     }}
  </code></pre>
  
  <p>In theory, while the user sees the output "it's ... turn to edit the file." this should loop in the background, checking if the file has already been updated, and if yes, redirect the user. </p>
  
  <p>Practically this heavily affects server perfomance (I'm on shared hosting) until it breaks with a memory exceeded error message.</p>
  
  <p>Is something wrong with the code? Or is it generally a bad idea to use a while loop in this case?</p>
  
  <p>Thanks in advance!</p>