stanley-king преди 3 години
родител
ревизия
630c68636d
променени са 4 файла, в които са добавени 94 реда и са изтрити 4 реда
  1. 2 2
      data/config/dev/base.ini.php
  2. 1 1
      docker/compose/stanley/cli/docker-compose.yml
  3. 82 0
      test/TestOrderErr.php
  4. 9 1
      test/TestRefillClear.php

+ 2 - 2
data/config/dev/base.ini.php

@@ -45,8 +45,8 @@ $config['gip'] 		= 0;
 $config['dbdriver'] = 'mysqli';
 $config['tablepre']	= 'lrlz_';
 
-//define('SSH_TUNEL_PROD','local');
-define('SSH_TUNEL_PROD','xyz');
+define('SSH_TUNEL_PROD','local');
+//define('SSH_TUNEL_PROD','xyz');
 //define('SSH_TUNEL_PROD','lingzh');
 //define('SSH_TUNEL_PROD','xyztest');
 

+ 1 - 1
docker/compose/stanley/cli/docker-compose.yml

@@ -8,7 +8,7 @@ services:
       - ../conf/php/php-debug.ini:/usr/local/etc/php/php.ini
       - ../../../../:/var/www/html
       - /Volumes/Transcend/upload:/var/www/html/data/upload
-#      - /Volumes/Data/pdlog:/var/www/html/data/log/pdlog
+      - /Volumes/Data/pdlog:/var/www/html/data/log/pdlog
       - /Users/stanley-king/work/PHPProject/shoplog:/var/www/html/data/log
       - /Users/stanley-king/work/PHPProject/amount:/var/www/html/data/amount
     container_name: "panda-php"

+ 82 - 0
test/TestOrderErr.php

@@ -219,4 +219,86 @@ line;
         fclose($file);
     }
 
+    public function testFilter()
+    {
+        $start_time = '2021-12-28 15:22:00';
+        $end_time = '2021-12-28 15:41:00';
+
+        $files = ['45' => 'xaj'];
+        $prefix = BASE_DATA_PATH . "/log/pdlog";
+        foreach ($files as $path => $name) {
+            $input = "{$prefix}/{$path}/{$name}";
+            $outpath = "{$prefix}/{$path}";
+            $this->filter_time($input,$outpath,$start_time,$end_time);
+        }
+    }
+
+    private function filter_time($input_file,$outpath,$start_time,$end_time)
+    {
+        $start = strtotime($start_time);
+        $end = strtotime($end_time);
+
+        $reader = function ($fp) use ($start, $end)
+        {
+            while(!feof($fp))
+            {
+                $line = fgets($fp);
+                $ret = preg_match('/\[cordispatcher[\s]+(?P<pid>[\d]+)-[\d]+[\s]+(?P<time>[\d-]+[\s]{1}[\d:]+)[\s]{1}/u', $line, $matches);
+                if ($ret)
+                {
+                    $time = strtotime($matches['time']);
+                    if ($time < $start) {
+                        continue;
+                    }
+                    elseif($time > $end) {
+                        break;
+                    }
+                    else {
+                        yield $line;
+                    }
+                }
+            }
+        };
+
+
+        $filter_time = function ($line)
+        {
+            $ret = preg_match('/\[cordispatcher[\s]+(?P<pid>[\d]+)-[\d]+[\s]+(?P<time>[\d-]+[\s]{1}[\d:]+)[\s]{1}/u', $line, $matches);
+            if ($ret) {
+                $pid = intval($matches['pid']);
+                return $pid;
+            }
+
+            return 0;
+        };
+        $pid_fp = [];
+        $spliter = function ($pid,$line) use ($outpath,$pid_fp)
+        {
+            if(array_key_exists($pid,$pid_fp)) {
+                $fp = $pid_fp[$pid];
+            } else {
+                $name = "{$outpath}/{$pid}.log";
+                $fp = fopen($name,'w');
+                $pid_fp[$pid] = $fp;
+            }
+
+            fwrite($fp,$line);
+        };
+
+        $input = fopen($input_file,'r');
+
+        $lines = $reader($input);
+        foreach ($lines as $line)
+        {
+            $pid = $filter_time($line);
+            if($pid > 0) {
+                $spliter($pid,$line);
+            }
+        }
+
+        fclose($input);
+        foreach ($pid_fp as $pid => $fp) {
+            fclose($fp);
+        }
+    }
 }

+ 9 - 1
test/TestRefillClear.php

@@ -129,7 +129,7 @@ class TestRefillClear extends TestCase
         $this->clear($start_date,$end_date);
     }
 
-    //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testDecember15)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
+    //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testDecember16)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
     public function testDecember16()
     {
         $start_date = strtotime('2021-12-16');
@@ -137,6 +137,14 @@ class TestRefillClear extends TestCase
         $this->clear($start_date,$end_date);
     }
 
+    //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testDecember20)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
+    public function testDecember20()
+    {
+        $start_date = strtotime('2021-12-20');
+        $end_date   = strtotime('2022-12-28');
+        $this->clear($start_date,$end_date);
+    }
+
     public function testAllRecords()
     {
         $rorder_getter = function ($mchid,$mch_order,$mod_refill)