forked from LightsOnHudson/FPP-Plugin-EventDate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lock.helper.php
executable file
·59 lines (45 loc) · 1.34 KB
/
lock.helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class lockHelper {
private static $pid;
function __construct() {}
function __clone() {}
private static function isrunning() {
$pids = explode(PHP_EOL, `ps -e | awk '{print $1}'`);
if(in_array(self::$pid, $pids))
return TRUE;
return FALSE;
}
public static function lock() {
global $argv;
$lock_file = LOCK_DIR.$argv[0].LOCK_SUFFIX;
if(file_exists($lock_file)) {
//return FALSE;
// Is running?
self::$pid = file_get_contents($lock_file);
if(self::isrunning()) {
logEntry("==".self::$pid."== Already in progress...");
//error_log("==".self::$pid."== Already in progress...");
return FALSE;
}
else {
logEntry("==".self::$pid."== Previous job died abruptly...");
//error_log("==".self::$pid."== Previous job died abruptly...");
}
}
self::$pid = getmypid();
file_put_contents($lock_file, self::$pid);
logEntry("==".self::$pid."== Lock acquired, processing the job...");
//error_log("==".self::$pid."== Lock acquired, processing the job...");
return self::$pid;
}
public static function unlock() {
global $argv;
$lock_file = LOCK_DIR.$argv[0].LOCK_SUFFIX;
if(file_exists($lock_file))
unlink($lock_file);
logEntry("==".self::$pid."== Releasing lock...");
//error_log("==".self::$pid."== Releasing lock...");
return TRUE;
}
}
?>