|
@@ -64,6 +64,8 @@ class InotifyMonitor {
|
|
|
$this->redis->select(1);
|
|
|
$result = $this->redis->ping();
|
|
|
echo "redis连接结果=>".$result.PHP_EOL;
|
|
|
+ $this->scan_file($paths[0]);
|
|
|
+
|
|
|
}
|
|
|
public function __destruct( ){
|
|
|
if (!empty($this->fds)) {
|
|
@@ -124,6 +126,7 @@ class InotifyMonitor {
|
|
|
|
|
|
public function run( ){
|
|
|
echo '我开始运行了'.PHP_EOL;
|
|
|
+
|
|
|
|
|
|
while (true) {
|
|
|
$reads = $this->fds;
|
|
@@ -177,14 +180,37 @@ class InotifyMonitor {
|
|
|
public function set_redis($data)
|
|
|
{
|
|
|
if(!strstr($data,'md5'))
|
|
|
- {
|
|
|
+ {
|
|
|
+ rename($data,$data.'.redis');
|
|
|
$this->redis->lpush('redis_to_kafka',$data);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
+ //扫描目录下所有没有上传到redis文件
|
|
|
+ public function scan_file($dir)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
|
|
|
// //调用函数
|