gwang 5 жил өмнө
parent
commit
960f3610bb

+ 7 - 12
Gameserver/Amfphp/test.php

@@ -10,15 +10,10 @@ echoLine("phpver:" . PHP_VERSION);
 
 
 
-for ($i = 0; $i < 5; $i++) {
-    switch ($i) {
-        case 1:
-        case 3:
-        case 5:
-            echoLine($i . " is 奇数");
-            break;
-        default :
-            echoLine($i . " is 偶数");
-            break;
-    }
-}
+
+CLog::info("我们的祖国像花园,花园里花朵真鲜艳.1");
+CLog::info("我们的祖国像花园,花园里花朵真鲜艳.2");
+CLog::warn("我们的祖国像花园,花园里花朵真鲜艳.3");
+CLog::warn("我们的祖国像花园,花园里花朵真鲜艳.4");
+CLog::warn("和暖的阳光照耀着我们,每个人的脸上都笑开颜.5");
+

+ 47 - 62
Gameserver/Amfphp/util/CLog.php

@@ -123,12 +123,17 @@ class CLog {
      * 将缓存中的数据写入存储设备并清除缓存
      */
     public static function flush() {
-        self::flush2File(enum_LogLevel::Info);                                  # 普通信息写到本地文件
-        self::flush2File(enum_LogLevel::Warn);
-        if (GAME_ONLINE) {
-            self::flush2Redis(enum_LogLevel::Err);                              # 外网错误日志写入redis
+        if (GAME_ONLINE) {                                                      # 外网错误日志写入redis
+            self::flush2Redis(enum_LogLevel::Info);
+            self::flush2Redis(enum_LogLevel::Warn);
+            self::flush2Redis(enum_LogLevel::Err);
         } else {
-            self::flush2File(enum_LogLevel::Err);                               # 内网错误日志写入本地文件
+//            self::flush2MySQL(enum_LogLevel::Info);                             # 内网写入MySQL
+//            self::flush2MySQL(enum_LogLevel::Warn);
+//            self::flush2MySQL(enum_LogLevel::Err);
+            self::flush2Redis(enum_LogLevel::Info);
+            self::flush2Redis(enum_LogLevel::Warn);
+            self::flush2Redis(enum_LogLevel::Err);
         }
     }
 
@@ -178,6 +183,40 @@ class CLog {
         }
     }
 
+    /**
+     * 将缓存中的数据写入存储设备(mysql)并清除缓存
+     * @type int/enum_LogLevel 日志类型
+     */
+    private static function flush2MySQL($type) {
+        $typename = strval(new enum_LogLevel($type));
+        $key = "log-" . $typename;
+        $arr = self::$$typename;                                                # 取对应类型的数组
+
+        if (count($arr) > 0) {
+            // 创建表
+            $sql = "create table  if not exists `$key` (`row` INT(11) NOT NULL AUTO_INCREMENT COMMENT '自增行号', `msg` TEXT NULL COMMENT '错误消息内容',	PRIMARY KEY (`row`)) COLLATE='utf8_general_ci' ENGINE=InnoDB;";
+            daoInst()->exec($sql);
+            // 插入数据
+            $data = array();
+            array_map(function($v) use(&$data) {
+                $s = daoInst()->quote($v);
+                var_dump($s);
+                $data[] = "(" . $s . ")";
+            }, $arr);
+            $sql_insert = "insert into `$key` (`msg`) values " . implode(',', $data) . " ;";
+            daoInst()->exec($sql_insert);
+            // 检查表大小
+            $n = daoInst()->select()->from("`$key`")->count();                  # 查一下当前表大小  
+            $max = 150000;                                                      # 最多保留15万条记录
+            $del_once = 10000;                                                  # 超过15万,清理一次,一次删除1万条
+            if ($n > $max) {
+                $sql = "delete from `$key` order by `row` limit $del_once ;";   # 一次清理一批
+                daoInst()->exec($sql);
+            }
+//            self::$$typename = array();                                         # 清空数据
+        }
+    }
+
 //
 // 避免异常导致缓存丢失, 付费模块的日志直接写入文件
 // <editor-fold defaultstate="collapsed" desc=" 付费相关日志, 无缓存 ">
@@ -195,16 +234,6 @@ class CLog {
         }
     }
 
-    /**
-     * 输出日志 到gift.log
-     * @param mixed $msg 参数是字符串则直接输出,否则调用json_encode
-     * @deprecated since version 0.1
-     */
-    public static function giftlog($msg) {
-        $fileName = self::GetDir() . "gift.log";
-        self::Log2File($fileName, $msg);
-    }
-
     /**
      * 向文件写入日志
      * @global int $zoneid
@@ -266,54 +295,10 @@ class CLog {
         }
     }
 
-// </editor-fold>
-//
-// <editor-fold defaultstate="collapsed" desc=" 待实现">
-
-    /**
-     *  将redis中昨天的日志数据输出到磁盘存储介质比如MySQL中.
-     *  配合crontable 定时将redis中的日志转存到成本较低的MySQL中方便查阅记录.
-     *  而在MySQL中的数据则进行定期备份,比如一个月之后将上个月的数据转储为sql文件,然后从数据库中清除.
-     */
-    public static function dump() {
-        throw new \Exception('uncompleted');
-        $redis = gMem();
-        $tsday = TimeUtil::dtYesterday();  // 20160702
-        $db = CPayInit();
-        $sk = "game-run-log-" . $tsday;
-        set_time_limit(0);  // 这里要取消超时限制
-        self::_insert2mysql($redis, $db, $sk . "-info");
-        self::_insert2mysql($redis, $db, $sk . "-log");
-        self::_insert2mysql($redis, $db, $sk . "-err");
-        $db->close();
-    }
-
-    /**
-     * 插入记录
-     * @param CRedisUtil $redis
-     * @param CDBUtil $db
-     * @param string $key
-     */
-    private static function _insert2mysql($redis, $db, $key) {
-        $len = 1000; # 一个批次插入1000条记录能达到相对较优的效率了. (100M内网/1000M本机测试,单条记录长度约为200个字节)
-        $arr = $redis->lrange($key, 0, $len - 1);
-        while (count($arr) > 0) {
-            $values = array();
-            $sql = 'insert into log201607 (type,ts,tag,msg) values ';
-            foreach ($arr as $s) {
-                $values[] = "(" . enum_LogLevel::Err . ", $s)";
-            }
-            $sql .= implode(',', $values);
-            $db->query($sql);
-            $redis->ltrim($key, $len, -1);
-            $arr = $redis->lrange($key, 0, $len - 1);
-        }
-    }
-
 // </editor-fold>
 //
 }
 
-//if (!GAME_ONLINE) {                                                             # 除了现网
-CLog::SetLogLevel(enum_LogLevel::All);                                      # 开启所有级别的日志输出
-//}
+if (!GAME_ONLINE) {                                                             # 除了现网
+    CLog::SetLogLevel(enum_LogLevel::All);                                      # 开启所有级别的日志输出
+}

+ 25 - 23
Gameserver/Amfphp/util/dao.php

@@ -799,7 +799,7 @@ class dao {
             $i = 0;
             while ($row = $stmt->fetch()) {
                 $key ? $rows[$row->$key] = $row : $rows[] = $row;
-                $i ++;
+                $i++;
                 if ($i == $max)
                     break;
             }
@@ -807,7 +807,7 @@ class dao {
         }
         /* Others, call the method in sql class. */ else {
             /* Create the max counts of sql class methods, and then create $arg0, $arg1... */
-            for ($i = 0; $i < SQL::MAX_ARGS; $i ++) {
+            for ($i = 0; $i < SQL::MAX_ARGS; $i++) {
                 ${"arg$i"} = isset($funcArgs[$i]) ? $funcArgs[$i] : null;
             }
             $this->sqlobj->$funcName($arg0, $arg1, $arg2);
@@ -855,7 +855,7 @@ class dao {
             unset($funcArgs[0]);
             unset($funcArgs[1]);
 
-            for ($i = 0; $i < VALIDATER::MAX_ARGS; $i ++) {
+            for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
                 ${"arg$i"} = isset($funcArgs[$i + 2]) ? $funcArgs[$i + 2] : null;
             }
             $checkFunc = 'check' . $funcName;
@@ -880,7 +880,7 @@ class dao {
         if (!$condition)
             return $this;
         $funcArgs = func_get_args();
-        for ($i = 0; $i < VALIDATER::MAX_ARGS; $i ++) {
+        for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
             ${"arg$i"} = isset($funcArgs[$i + 3]) ? $funcArgs[$i + 3] : null;
         }
         $this->check($fieldName, $funcName, $arg0, $arg1, $arg2);
@@ -898,7 +898,7 @@ class dao {
     public function batchCheck($fields, $funcName) {
         $fields = explode(',', str_replace(' ', '', $fields));
         $funcArgs = func_get_args();
-        for ($i = 0; $i < VALIDATER::MAX_ARGS; $i ++) {
+        for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
             ${"arg$i"} = isset($funcArgs[$i + 2]) ? $funcArgs[$i + 2] : null;
         }
         foreach ($fields as $fieldName)
@@ -920,7 +920,7 @@ class dao {
             return $this;
         $fields = explode(',', str_replace(' ', '', $fields));
         $funcArgs = func_get_args();
-        for ($i = 0; $i < VALIDATER::MAX_ARGS; $i ++) {
+        for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
             ${"arg$i"} = isset($funcArgs[$i + 2]) ? $funcArgs[$i + 2] : null;
         }
         foreach ($fields as $fieldName)
@@ -949,7 +949,7 @@ class dao {
             $options = array();
             if (isset($validater['options']))
                 $options = array_values($validater['options']);
-            for ($i = 0; $i < VALIDATER::MAX_ARGS; $i ++) {
+            for ($i = 0; $i < VALIDATER::MAX_ARGS; $i++) {
                 ${"arg$i"} = isset($options[$i]) ? $options[$i] : null;
             }
             $this->check($fieldName, $validater['rule'], $arg0, $arg1, $arg2);
@@ -1428,7 +1428,7 @@ class sql {
      * @return object the sql object.
      */
     public function where($arg1, $arg2 = null, $arg3 = null) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         if ($arg3 !== null) {
             $value = $this->quote($arg3);
@@ -1449,7 +1449,7 @@ class sql {
      * @return object the sql object.
      */
     public function andWhere($condition) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " AND $condition ";
         return $this;
@@ -1463,7 +1463,7 @@ class sql {
      * @return object the sql object.
      */
     public function orWhere($condition) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " OR $condition ";
         return $this;
@@ -1477,7 +1477,7 @@ class sql {
      * @return object the sql object.
      */
     public function eq($value) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " = " . $this->quote($value);
         return $this;
@@ -1491,7 +1491,7 @@ class sql {
      * @return void the sql object.
      */
     public function ne($value) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " != " . $this->quote($value);
         return $this;
@@ -1505,7 +1505,7 @@ class sql {
      * @return object the sql object.
      */
     public function gt($value) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " > " . $this->quote($value);
         return $this;
@@ -1519,7 +1519,7 @@ class sql {
      * @return object the sql object.
      */
     public function ge($value) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " >= " . $this->quote($value);
         return $this;
@@ -1533,7 +1533,7 @@ class sql {
      * @return object the sql object.
      */
     public function lt($value) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " < " . $this->quote($value);
 
@@ -1564,7 +1564,7 @@ class sql {
      * @return object the sql object.
      */
     public function between($min, $max) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $min = $this->quote($min);
         $max = $this->quote($max);
@@ -1581,7 +1581,7 @@ class sql {
      */
     public function in($ids) {
 //        var_dump($ids);
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= self::dbIN($ids);
         return $this;
@@ -1609,7 +1609,7 @@ class sql {
      * @return object the sql object.
      */
     public function notin($ids) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= ' NOT ' . self::dbIN($ids);
         return $this;
@@ -1623,7 +1623,7 @@ class sql {
      * @return object the sql object.
      */
     public function like($string) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= " LIKE " . $this->quote($string);
         return $this;
@@ -1637,7 +1637,7 @@ class sql {
      * @return object the sql object.
      */
     public function notLike($string) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= "NOT LIKE " . $this->quote($string);
         return $this;
@@ -1652,7 +1652,7 @@ class sql {
      * @return object the sql object.
      */
     public function findInSet($str, $strList) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
         $this->sql .= "FIND_IN_SET(" . $str . "," . $strList . ")";
     }
@@ -1665,7 +1665,7 @@ class sql {
      * @return object the sql object.
      */
     public function orderBy($order) {
-        if ($this->inCondition and ! $this->conditionIsTrue)
+        if ($this->inCondition and!$this->conditionIsTrue)
             return $this;
 
         $order = str_replace(array('|', '', '_'), ' ', $order);
@@ -1757,8 +1757,10 @@ class sql {
      * @return mixed
      */
     public function quote($value) {
-        if ($this->magicQuote)
+        var_dump($value);
+        if ($this->magicQuote) {
             $value = stripslashes($value);
+        }
         return $this->dbh->quote($value);
     }
 

+ 1 - 5
Gameserver/nbproject/private/private.xml

@@ -11,10 +11,6 @@
         </file>
     </editor-bookmarks>
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
-        <group>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/HeroProc.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/base/CmdCode.php</file>
-            <file>file:/E:/www/ylsj2019/Gameserver/Amfphp/process/FightProc/SweepGatesProc.php</file>
-        </group>
+        <group/>
     </open-files>
 </project-private>