Explorar o código

FileMonitor排除文件

walkor %!s(int64=11) %!d(string=hai) anos
pai
achega
15de87aa12
Modificáronse 2 ficheiros con 27 adicións e 0 borrados
  1. 25 0
      workerman/Common/FileMonitor.php
  2. 2 0
      workerman/conf/conf.d/FileMonitor.conf

+ 25 - 0
workerman/Common/FileMonitor.php

@@ -88,8 +88,27 @@ class FileMonitor extends Man\Core\AbstractWorker
         $flag = $block ? 0 : MSG_IPC_NOWAIT;
         if(msg_receive(\Man\Core\Master::getQueueId(), self::MSG_TYPE_FILE_MONITOR, $msg_type, 10000, $message, true, $flag))
         {
+            // 被排除的路径
+            $exclude_path = array();
+            // 因为配置可能会被更改,所以每次都会重新从配置中查找排除路径
+            $config_exclude_path = $this->getExcludeFiles();
+            foreach($config_exclude_path as $path)
+            {
+                if($real_path = realpath($path))
+                {
+                    $exclude_path[] = $real_path;
+                }
+            }
             foreach($message as $file)
             {
+                foreach($exclude_path as $path)
+                {
+                    // 是被排除的文件
+                    if(0  === strpos($file, $path))
+                    {
+                        continue;
+                    }
+                }
                 if(!isset($this->filesToInotify[$file]))
                 {
                     $stat = @stat($file);
@@ -165,4 +184,10 @@ class FileMonitor extends Man\Core\AbstractWorker
         }
     }
     
+    protected function getExcludeFiles()
+    {
+        $exclude_path = \Man\Core\Lib\Config::get($this->workerName.'.exclude_path');
+        return (array)$exclude_path;
+    }
+    
 } 

+ 2 - 0
workerman/conf/conf.d/FileMonitor.conf

@@ -6,3 +6,5 @@ worker_file = Common/FileMonitor.php
 start_workers=1
 ;以哪个用户运行该worker进程
 user=root
+;排除文件或者目录
+exclude_path[]=./logs/