title: Running a PHP script every 5 minutes and avoiding race conditions
body: <p>I have a php script that needs to run once every 5 minutes. Currently I'm using a cron job to run it (and it works great) but my host only allows a minimum time of 15 minutes.</p>
  
  <p>So my question is, can I use visitors to trigger the running of a php script every 5 minutes. I can easily just record the last time it ran, and re-run it based on elapsed time.</p>
  
  <p>However, I'm worried about race conditions. It is important that the script only gets run <em>once</em> every 5 minutes.</p>
  
  <p>My script takes about 60 seconds to run. It writes to a couple files during this time. If the script ran more than once it would corrupt files. Also, if I get no vistors for 10 minutes, then running once when the next vistor arrives is fine.</p>
  
  <p>Is there some standard way to accomplish this task?</p>
  
  <p>Thanks!</p>