|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+require './DahuaUtil.php';
|
|
|
class InotifyMonitor {
|
|
|
|
|
|
const MONITOR_EVENT = IN_CLOSE_WRITE;
|
|
@@ -55,18 +56,37 @@ class InotifyMonitor {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // if (!empty($post_url)) {
|
|
|
- // $this->url = $post_url;
|
|
|
- // }
|
|
|
+
|
|
|
$this->redis = new Redis();
|
|
|
- $this->redis->pconnect($ip,$post,2.5);
|
|
|
- $this->redis->auth($password); //设置密码
|
|
|
- $this->redis->select(1);
|
|
|
- $result = $this->redis->ping();
|
|
|
- echo "redis连接结果=>".$result.PHP_EOL;
|
|
|
- $this->scan_file($paths[0]);
|
|
|
+ try{
|
|
|
+ $this->redis->pconnect($ip,$post,2.5);
|
|
|
+ $this->redis->auth($password); //设置密码
|
|
|
+ $this->redis->select(1);
|
|
|
+ $result = $this->redis->ping();
|
|
|
+ if($result=='pong')
|
|
|
+ {
|
|
|
+ echo "redis连接成功";
|
|
|
+ DahuaUtil::rlog('redis连接成功');
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DahuaUtil::rlog("redis连接失败=>".$result.PHP_EOL);
|
|
|
+ echo "redis连接失败=>".$result.PHP_EOL;
|
|
|
+ }
|
|
|
+ //扫描未存起来的redis文件
|
|
|
+ DahuaUtil::rlog("扫描没有监听到的文件");
|
|
|
+ $this->scan_file($paths[0]);
|
|
|
+ }catch (Exception $e){
|
|
|
+
|
|
|
+ DahuaUtil::rlog("redis连接异常".$e->getMessage());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
public function __destruct( ){
|
|
|
if (!empty($this->fds)) {
|
|
|
foreach ($this->fds as $fd) {
|
|
@@ -102,7 +122,7 @@ class InotifyMonitor {
|
|
|
stream_set_blocking($this->fds[$fid], 0);
|
|
|
$this->paths[$fid] = $dir;
|
|
|
$this->wds[$fid] = inotify_add_watch($this->fds[$fid], $dir, self::MONITOR_EVENT);
|
|
|
- //遍历目录下文�?
|
|
|
+ //遍历目录下文
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
if ($file == '.' || $file == '..') {
|
|
|
continue;
|
|
@@ -125,6 +145,7 @@ class InotifyMonitor {
|
|
|
|
|
|
|
|
|
public function run( ){
|
|
|
+
|
|
|
echo '我开始运行了'.PHP_EOL;
|
|
|
|
|
|
|
|
@@ -181,40 +202,23 @@ class InotifyMonitor {
|
|
|
{
|
|
|
if(!strstr($data,'md5'))
|
|
|
{
|
|
|
- rename($data,$data.'.redis');
|
|
|
+ if(rename($data,$data.'.redis'))
|
|
|
+ {
|
|
|
+ $data=$data.'.redis';
|
|
|
+ }
|
|
|
$this->redis->lpush('redis_to_kafka',$data);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
//扫描目录下所有没有上传到redis文件
|
|
|
- public function scan_file($dir)
|
|
|
+ public function scan_file()
|
|
|
{
|
|
|
- if(is_file($dir))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- $files = scandir($dir);
|
|
|
- foreach($files as $k=>$filename) {//务必使用!==,防止目录下出现类似文件名“0”等情况
|
|
|
- if ($filename != "." && $filename != ".." && !strstr($filename,'.redis')&&!strstr($filename,'.md5')&&is_file($dir.'/'.$filename)) {
|
|
|
- $data = $dir.'/'.$filename;
|
|
|
- rename($data,$data.'.redis');
|
|
|
- $this->redis->lpush('redis_to_kafka',$data);
|
|
|
- }
|
|
|
- }
|
|
|
- closedir($dir);
|
|
|
+ echo shell_exec("php /home/wwwroot/nbfd_tp3/index.php listening_file_create/scan_no_listening");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
- // //调用函数
|
|
|
- // $path = "/test";
|
|
|
- // $inotify = new InotifyMonitor([$path]);
|
|
|
- // echo '进入运行�?;
|
|
|
- // $inotify->run();
|