Created
October 26, 2014 16:47
-
-
Save drakakisgeo/2c756f2e6c1d0c3720e5 to your computer and use it in GitHub Desktop.
Preventing Cron Job Collision (File system lock file - Laravel indatus/dispatcher)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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