stanley-king пре 6 година
родитељ
комит
506b531140
2 измењених фајлова са 53 додато и 17 уклоњено
  1. 22 16
      logmonitor.php
  2. 31 1
      test/TestLog.php

+ 22 - 16
logmonitor.php

@@ -5,32 +5,19 @@
  * Date: 2018/8/30
  * Time: 下午2:51
  */
-ini_set('ignore_user_abort', true);
-set_time_limit(0);
+//ini_set('ignore_user_abort', true);
+//set_time_limit(0);
 define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
 
 require_once (BASE_ROOT_PATH . '/fooder.php');
-Base::run_util();
-$monitor = new Monitor();
-
-while (true) {
-    /*$monitor->readOne();
-    usleep(100);*/
-    $monitor->run_loop();
-}
 
 class Monitor
 {
     private $_ptr_pos = 0;
-
     private $_mark = "]";
-
     private $date_now;
-
     private $input_fname;
-
     private $_fd_input;
-
     private $_fd_log;
 
     public function __construct()
@@ -61,6 +48,7 @@ class Monitor
                     $this->setInputFd();
                 }
 
+
                 usleep(1000);
             }
 
@@ -115,6 +103,7 @@ class Monitor
 
     private function setInputFd()
     {
+
         $date = date("Ymd");
         $file_name = BASE_DATA_PATH. DS. 'log'. DS. $date. ".log";
         @fclose($this->_fd_input);
@@ -133,4 +122,21 @@ class Monitor
         //$msg .= "\r\n";
         @fwrite($this->_fd_log, $msg);
     }
-}
+}
+
+//function monitor_work()
+//{
+//    Base::run_util();
+//    $monitor = new Monitor();
+//
+//    while (true) {
+//        $monitor->run_loop();
+//    }
+//}
+
+function monitor_work()
+{
+    $fd = @fopen(BASE_ROOT_PATH . "/data/log/20180831.log", "r+");
+
+}
+

+ 31 - 1
test/TestLog.php

@@ -1128,7 +1128,6 @@ class TestLog extends PHPUnit_Framework_TestCase
         $info = pathinfo($url);
 
         if(!file_exists($path)) {
-//            $pic_url = $info['dirname'] . '/' . urlencode($info['basename']);
             $pic_url = $info['dirname'] . '/' . str_replace(' ','%20',$info['basename']);
             exec("wget -O $path $pic_url");
         }
@@ -1145,4 +1144,35 @@ class TestLog extends PHPUnit_Framework_TestCase
             return false;
         }
     }
+    public function testMonitor()
+    {
+        $fd = @fopen(BASE_ROOT_PATH . "/data/log/20180831.log", "c+");
+
+        while (true)
+        {
+            $line = fgets($fd);
+            if($line !== false) echo $line;
+            if(feof($fd)) {
+                usleep(1000000);
+            }
+        }
+    }
+
+    public function testMonitorSelect()
+    {
+        $fd = @fopen(BASE_ROOT_PATH . "/data/log/20180831.log", "c+");
+
+        while (true)
+        {
+            $wfds = $xfds = array();
+            $rfds = array($this->_sock);
+            $res = stream_select($rfds, $wfds, $xfds, 0, 0);
+            
+            $line = fgets($fd);
+            if($line !== false) echo $line;
+            if(feof($fd)) {
+                usleep(1000000);
+            }
+        }
+    }
 }