title: Running a PHP script or function at an exact point in the future
body: <p>I'm currently working on a browser game with a PHP backend that needs to perform certain checks at specific, changing points in the future. Cron jobs don't really cut it for me as I need precision at the level of seconds. Here's some background information:</p>
  
  <ul>
  <li>The game is multiplayer and turn-based</li>
  <li>On creation of a game room the game creator can specify the maximum amount of time taken per action (30 seconds - 24 hours)</li>
  </ul>
  
  <p>Once a player performs an action, they should only have the specified amount of time to perform the next, or the turn goes to the player next in line.</p>
  
  <p>For obvious reasons I can't just keep track of time through Javascript, as this would be far too easy to manipulate. I also can't schedule a cron job every minute as it may be up to 30 seconds late.</p>
  
  <p>What would be the most efficient way to tackle this problem? I can't imagine querying a database every second would be very server-friendly, but it is the direction I am currently leaning towards[1].</p>
  
  <p>Any help or feedback would be much appreciated!</p>
  
  <p>[1]:</p>
  
  <ul>
  <li>A user makes a move</li>
  <li>A PHP function is called that sets <em>'switchTurnTime'</em> in the MySQL table's game row to <em>'TIMESTAMP'</em></li>
  <li>A PHP script that is always running in the background queries the table for any games where the <em>'switchTurnTime'</em> has passed, switches the turn and resets the time.</li>
  </ul>