Prevent duplicate Stripe payment bookings and overlapping cron runs

This commit is contained in:
johnnyq
2026-07-27 15:22:16 -04:00
parent 815802fb7c
commit 65de8c35e6
3 changed files with 58 additions and 2 deletions

View File

@@ -8,6 +8,14 @@ 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
// handle is held for the life of the process and released when it exits.
$cron_lock_handle = fopen(sys_get_temp_dir() . '/itflow_cron.lock', 'c');
if ($cron_lock_handle === false || !flock($cron_lock_handle, LOCK_EX | LOCK_NB)) {
die("Cron is already running - exiting.\n");
}
require_once "../config.php";
// Set Timezone