mirror of
https://github.com/itflow-org/itflow
synced 2026-08-16 20:45:12 +00:00
Scope the cron lock per install so instances don't block each other
Report an unopenable cron lock file instead of claiming cron is running
This commit is contained in:
@@ -9,10 +9,15 @@ if (php_sapi_name() !== 'cli') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only one run at a time. Autopay charges cards, so an overlapping run (the previous
|
// 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
|
// run still going when the next one fires) could bill the same invoice twice. The lock
|
||||||
// handle is held for the life of the process and released when it exits.
|
// file is named per install so separate ITFlow instances on one host don't block each
|
||||||
$cron_lock_handle = fopen(sys_get_temp_dir() . '/itflow_cron.lock', 'c');
|
// other, and the handle is held for the life of the process, released when it exits.
|
||||||
if ($cron_lock_handle === false || !flock($cron_lock_handle, LOCK_EX | LOCK_NB)) {
|
$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");
|
die("Cron is already running - exiting.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user