PHP loop acting as cronjob[ensure only one instance running]

后端 未结 2 776
一向
一向 2020-12-18 14:12

I have a multi part question for a php script file. I am creating this file that updates the database every second. There is no other modeling method, it has to be done ever

2条回答
  •  旧时难觅i
    2020-12-18 14:54

    You can't always rely on the lock within the script itself, as stated in the comment to previous answer. This might be a solution.

    #Mins  Hours  Days   Months  Day of week
      *     *      *      *       *   lockfile -r 0 /tmp/the.lock; php parse_tweets.php; rm -f /tmp/the.lock
      *     *      *      *       *   lockfile -r 0 /tmp/the.lock; php php get_tweets.php; rm -f /tmp/the.lock
    

    This way even if the scripts crashes, the lockfile will be released. Taken from here: https://unix.stackexchange.com/a/158459

提交回复
热议问题