Skip to content

Commit

Permalink
replaced database lock with flock
Browse files Browse the repository at this point in the history
  • Loading branch information
renlok committed Dec 13, 2017
1 parent 9da4811 commit 1a73eb9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 16,11 @@
exit();
}

// timeout for the cron in seconds
$cron_timeout = 5 * 60;
$fp = fopen("/cache/lock.txt", "w ");

// check if the cron is running or has it timed out
if ($system->SETTINGS['cronRunning'] == 0 || ($system->SETTINGS['cronRunning'] $cron_timeout) < time()) {
$system->writesetting("cronRunning", time(), "int");

include INCLUDE_PATH . 'functions_cron.php';
// do an exclusive lock
if (flock($fp, LOCK_EX | LOCK_NB)) {
include_once INCLUDE_PATH . 'functions_cron.php';

// initialize cron script
printLog('=============== STARTING CRON SCRIPT: ' . date('F d, Y H:i:s'));
Expand Down Expand Up @@ -624,5 621,7 @@

// finish cron script
printLog("=========================== ENDING CRON: " . date('F d, Y H:i:s') . "\n");
$system->writesetting("cronRunning", 0, "int");
flock($fp, LOCK_UN); // release the lock
}

fclose($fp);

0 comments on commit 1a73eb9

Please sign in to comment.