title: How to detect whether a PHP script is already running?
body: <p>I have a cron script that executes a PHP script every 10 minutes.  The script checks a queue and processes the data in the queue.  Sometimes the queue has enough data to last over 10 minutes of processing, creating the potential of two scripts trying to access the same data.  I want to be able to detect whether the script is already running to prevent launching multiple copies of the script.  I thought about creating a database flag that says that a script is processing, but if the script were ever to crash it would leave it in the positive state.  Is there an easy way to tell if the PHP script is already running from withing a PHP or shell script?  </p>