mirror of
https://github.com/itflow-org/itflow
synced 2026-08-05 07:07:14 +00:00
Adds a shared flock guard used by all five cron entry points, keyed per
script and per install. Replaces the mail queue's own lock file, which was not atomic and could be deleted out from under a long run. Bounds the SMTP conversation so an unresponsive server cannot hold the lock. Recovers rows left at Sending by a run that died, which nothing previously picked up.
This commit is contained in:
@@ -8,18 +8,9 @@ if (php_sapi_name() !== 'cli') {
|
||||
die("This script must be run from the command line.\n");
|
||||
}
|
||||
|
||||
// Only one run at a time. Autopay charges cards, so an overlapping run (the previous
|
||||
// run still going when the next one fires) could bill the same invoice twice. The lock
|
||||
// file is named per install so separate ITFlow instances on one host don't block each
|
||||
// other, and the handle is held for the life of the process, released when it exits.
|
||||
$cron_lock_file = sys_get_temp_dir() . '/itflow_cron_' . md5(__DIR__) . '.lock';
|
||||
$cron_lock_handle = fopen($cron_lock_file, 'c');
|
||||
if ($cron_lock_handle === false) {
|
||||
die("Cannot open the cron lock file at $cron_lock_file - check permissions and open_basedir.\n");
|
||||
}
|
||||
if (!flock($cron_lock_handle, LOCK_EX | LOCK_NB)) {
|
||||
die("Cron is already running - exiting.\n");
|
||||
}
|
||||
// Prevent overlapping runs of this script
|
||||
$cron_lock_script = __FILE__;
|
||||
require_once "../includes/cron_lock.php";
|
||||
|
||||
require_once "../config.php";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user