Skip to content

Preventing Cron Job Collision

Note

Prevents jobs to collide if they take longer to run than the frequency itself

  1. $fp = fopen(‘/tmp/lock.txt’, ‘r+’);
  2. if(!flock($fp, LOCK_EX | LOCK_NB)) {
  3.    echo ‘Unable to obtain lock’;
  4.    exit(-1);
  5. }
  6. /* … */
  7. fclose($fp);