How to detect whether a PHP script is already running?

后端 未结 9 1335
借酒劲吻你
借酒劲吻你 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:34

    You can use new Symfony 2.6 LockHandler. Source

    $lock = new LockHandler('update:contents');
    if (!$lock->lock()) {
        echo 'The command is already running in another process.';
    }
    

提交回复
热议问题