title: What is the best way to run a continuous loop in php that only runs if it's not already running?
body: <p>LAMP stack on Ubuntu 18.04:</p>
  
  <p>I have a php loop that I want to continuously run. It is my understanding that Apache will spawn a thread per script that is executing and give one core to it and that's effectively what I'd like to do: Have a php script that constantly loops, processing things as it needs to.</p>
  
  <p>I've seen methods of running a cron every minute that create a file and then delete it when it is done but what happens when the script takes 61 seconds to execute and then it's just sitting around not doing anything for 59 seconds. Or if the script crashes and doesn't delete the file.</p>
  
  <p>Before doing this the wrong way, I wanted to find out what the <em>right</em> way is.</p>