From 31a6d42de4be9cb20317a7744190c891cd1ded55 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 25 Sep 2007 04:23:29 +0100 Subject: [PATCH] lock checking in update_feeds.php --- functions.php | 20 +++++++++++--------- update_feeds.php | 11 ++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/functions.php b/functions.php index 163b4adda..116082988 100644 --- a/functions.php +++ b/functions.php @@ -1720,17 +1720,19 @@ } function file_is_locked($filename) { - error_reporting(0); - $fp = fopen($filename, "r"); - error_reporting(DEFAULT_ERROR_LEVEL); - if ($fp) { - if (flock($fp, LOCK_EX | LOCK_NB)) { - flock($fp, LOCK_UN); + if (function_exists('flock')) { + error_reporting(0); + $fp = fopen($filename, "r"); + error_reporting(DEFAULT_ERROR_LEVEL); + if ($fp) { + if (flock($fp, LOCK_EX | LOCK_NB)) { + flock($fp, LOCK_UN); + fclose($fp); + return false; + } fclose($fp); - return false; + return true; } - fclose($fp); - return true; } return false; } diff --git a/update_feeds.php b/update_feeds.php index d06beb829..967d2e429 100644 --- a/update_feeds.php +++ b/update_feeds.php @@ -12,7 +12,15 @@ require_once "db.php"; require_once "db-prefs.php"; require_once "functions.php"; - require_once "magpierss/rss_fetch.inc"; + + $lock_filename = "update_feeds.lock"; + + $lock_handle = make_lockfile($lock_filename); + + if (!$lock_handle) { + die("error: Can't create lockfile ($lock_filename). ". + "Maybe another process is already running.\n"); + } $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); @@ -46,4 +54,5 @@ db_close($link); + unlink($lock_filename); ?>