walkor пре 11 година
родитељ
комит
b4bf6fd4c1

+ 7 - 0
applications/Statistics/Config/Config.php

@@ -0,0 +1,7 @@
+<?php
+namespace Statistics\Config;
+class Config
+{
+    // 数据源端口,会向这个端口发送udp广播获取ip,然后从这个端口以tcp协议获取统计信息
+    public static $ProviderPort = 55858;
+}

+ 12 - 1
applications/Statistics/Modules/admin.php

@@ -14,7 +14,7 @@ function admin()
             socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);
             $buffer = json_encode(array('cmd'=>'REPORT_IP'))."\n";
             // 广播
-            socket_sendto($socket, $buffer, strlen($buffer), 0, '255.255.255.255', \Statistics\Web\Config::$ProviderPort);
+            socket_sendto($socket, $buffer, strlen($buffer), 0, '255.255.255.255', \Statistics\Config\Config::$ProviderPort);
             // 超时相关
             $time_start = microtime(true);
             $global_timeout = 1;
@@ -68,6 +68,7 @@ function admin()
             {
                 $ip_list_str .= $ip."\r\n";
             }
+            saveServerIpListToCache();
             break;
         case 'save_server_list':
             if(empty($_POST['ip_list']))
@@ -93,6 +94,7 @@ function admin()
             {
                 $ip_list_str .= $ip."\r\n";
             }
+            saveServerIpListToCache();
             break;
         default:
             foreach(\Statistics\Lib\Cache::$ServerIpList as $ip)
@@ -104,4 +106,13 @@ function admin()
     include ST_ROOT . '/Views/header.tpl.php';
     include ST_ROOT . '/Views/admin.tpl.php';
     include ST_ROOT . '/Views/footer.tpl.php';
+}
+
+function saveServerIpListToCache()
+{
+    foreach(glob(ST_ROOT . '/Config/*.iplist.cache.php') as $php_file)
+    {
+        unlink($php_file);
+    }
+    file_put_contents(ST_ROOT . '/Config/'.time().'.iplist.cache.php', "<?php\n\\Statistics\\Lib\\Cache::\$ServerIpLis=".var_export(\Statistics\Lib\Cache::$ServerIpList,true).';');
 }

+ 6 - 1
applications/Statistics/Web/_init.php

@@ -2,4 +2,9 @@
 define('ST_ROOT', realpath(dirname(__FILE__) . '/..'));
 require_once ST_ROOT .'/Lib/functions.php';
 require_once ST_ROOT .'/Lib/Cache.php';
-require_once ST_ROOT .'/Web/config.php';
+require_once ST_ROOT .'/Config/Config.php';
+// 覆盖配置文件
+foreach(glob(ST_ROOT . '/Config/Cache/*.php')  as $php_file)
+{
+    require_once $php_file;
+}