How to detect whether a PHP script is already running?

后端 未结 9 1338
借酒劲吻你
借酒劲吻你 2021-01-31 11:26

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 ov

9条回答
  •  粉色の甜心
    2021-01-31 11:42

    If you are running Linux, this should work at the top of your script:

    $running = exec("ps aux|grep ". basename(__FILE__) ."|grep -v grep|wc -l");
    if($running > 1) {
       exit;
    }
    

提交回复
热议问题