]> git.wh0rd.org - tt-rss.git/commitdiff
lock checking in update_feeds.php
authorAndrew Dolgov <fox@madoka.spb.ru>
Tue, 25 Sep 2007 03:23:29 +0000 (04:23 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Tue, 25 Sep 2007 03:23:29 +0000 (04:23 +0100)
functions.php
update_feeds.php

index 163b4addaae36dc7488ab5d31d3b6cf608c0bfc3..1160829886d0bfe14e189b39395d739655c7a2e1 100644 (file)
        }
 
        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;
        }
index d06beb829de4079ac68e889a71ab6cd89f0c356a..967d2e4290e54ac5249e08bc5ef00a28c52cc88a 100644 (file)
        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);
 ?>