From 1a73eb9fc1e677dac3ab69b055ee28b1b22a1d20 Mon Sep 17 00:00:00 2001 From: Chris Dickenson Date: Wed, 13 Dec 2017 10:58:47 +0000 Subject: [PATCH] replaced database lock with flock --- cron.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cron.php b/cron.php index 0057b732..8f9b5f9f 100644 --- a/cron.php +++ b/cron.php @@ -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')); @@ -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); \ No newline at end of file