Skip to content

Instantly share code, notes, and snippets.

@drakakisgeo
Created October 26, 2014 16:47
Show Gist options
  • Save drakakisgeo/2c756f2e6c1d0c3720e5 to your computer and use it in GitHub Desktop.
Save drakakisgeo/2c756f2e6c1d0c3720e5 to your computer and use it in GitHub Desktop.
Preventing Cron Job Collision (File system lock file - Laravel indatus/dispatcher)
public function fire()
{
//// Preventing Cron Job Collision
$file = "/var/www/tick/cronlock";
$fp = fopen($file, 'r+');
if(!flock($fp, LOCK_EX | LOCK_NB)) {
$this->error('Cron is already running another task...');
exit(-1);
}
// Do MANY MANY STAFF
sleep(5);
$this->info('Done doing stuff!');
fclose($fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment