Repository navigation
Expand file tree
/
Copy pathstart_filemonitor.php
More file actions
64 lines (58 loc) · 1.69 KB
/
Copy pathstart_filemonitor.php
File metadata and controls
64 lines (58 loc) · 1.69 KB
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
<?php
if(!defined("RUN_DIR")){
define('RUN_DIR', __DIR__ . "/");
}
require_once '_lib/ape/helper.php';
require_once '_lib/ape/constant.php';
require_once '_lib/Autoloader.php';
require_once '_lib/ape/http/Http.php';
use Workerman\Worker;
use Workerman\Lib\Timer;
// 日志
Worker::$logFile = __DIR__ . "/log/" . APE['config'] ["logFile"];
// 访问日志
Worker::$stdoutFile = __DIR__ . "/log/" . APE['config'] ["stdoutFile"];
// watch Applications catalogue
$monitor_dir = realpath ( RUN_DIR );
$last_time_arr = array();
// worker
$worker = new Worker ();
$worker->name = 'FileMonitor';
$worker->reloadable = false;
$last_mtime = time ();
$worker->onWorkerStart = function () {
global $monitor_dir;
// watch files only in daemon mode
if (! Worker::$daemonize) {
// chek mtime of files per second
Timer::add ( 1, 'check_files_change', array (
$monitor_dir
) );
}
};
// check files func
function check_files_change($monitor_dir) {
global $last_time_arr;
// recursive traversal directory
$dir_iterator = new RecursiveDirectoryIterator ( $monitor_dir );
$iterator = new RecursiveIteratorIterator ( $dir_iterator );
foreach ( $iterator as $file ) {
// only check php files
if (pathinfo ( $file, PATHINFO_EXTENSION ) != 'php') {
continue;
}
if(!array_key_exists((string)$file,$last_time_arr)){
$last_time_arr[(string)$file] = $file->getMTime ();
}
if ($last_time_arr[(string)$file] < $file->getMTime ()) {
echo $file . " update and reload\n";
// send SIGUSR1 signal to master process for reload
posix_kill ( posix_getppid (), SIGUSR1 );
$last_time_arr[(string)$file] = $file->getMTime ();
break;
}
}
}
if(APE["WORKERMAN"] == "Workerman_win"){
Worker::runAll();
}