-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimers.php
executable file
·66 lines (56 loc) · 1.43 KB
/
timers.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
60
61
62
63
64
65
66
#!/usr/bin/php
<?php
require_once 'includes.php';
define("MY_DEVICE_ID", 97);
if (isset($_GET['DEBUG'])) {
define( 'DEBUG', TRUE );
$GLOBALS['debug'] = 1;
echo date("Y-m-d H:i:s").": ".RunTimers()." Timers Executed".CRLF;
exit;
}
class console{
public static function log($msg, $arr=array()){
$str = vsprintf($msg, $arr);
fprintf(STDERR, "$str\n");
}
}
if(version_compare(PHP_VERSION, "5.3.0", '<')){
// tick use required as of PHP 4.3.0
declare(ticks = 1);
}
pcntl_signal(SIGTERM, "signal_handler");
pcntl_signal(SIGHUP, "signal_handler");
pcntl_signal(SIGINT, "signal_handler");
if(version_compare(PHP_VERSION, "5.3.0", '>=')){
pcntl_signal_dispatch();
console::log("Signal dispatched");
}
while (true) {
RunTimers();
updateDLink(MY_DEVICE_ID);
sleep(10);
}
function cleanup(){
echo "Cleaning up\n";
exit (1);
}
function signal_handler($signo){
console::log("Caught a signal %d", array($signo));
switch ($signo) {
case SIGINT:
// handle restart tasks
cleanup();
break;
case SIGTERM:
// handle shutdown tasks
cleanup();
break;
case SIGHUP:
// handle restart tasks
cleanup();
break;
default:
fprintf(STDERR, "Unknown signal ". $signo);
}
}
?>