TestServer.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace loyalsoft;
  3. include_once __DIR__ . '/AppServer.php';
  4. require_once __DIR__ . '/../process/ActiveProc/CipheredBase32.php'; # 算法库
  5. /**
  6. * Description of TestServer
  7. * UT 测试
  8. * @author jgao
  9. */
  10. class TestServer {
  11. //put your code here
  12. /**
  13. * 入口函数专用测试
  14. * @param type $req
  15. */
  16. static public function testApi($req) {
  17. DebugHelper::debug($req);
  18. $app = new AppServer();
  19. $ret = $app->api(new Req($req));
  20. DebugHelper::debug($ret);
  21. }
  22. /**
  23. * 运行环境自检:
  24. * PHP 版本,扩展模块
  25. * redis操作性
  26. * sqldb操作性
  27. */
  28. static function selfTest() {
  29. echoLine("phpver: " . PHP_VERSION . PHP_EOL); # 打印下PHP版本
  30. SelfChecker::CheckConfig(); # 进行配置环境检测
  31. }
  32. public function testMemDelete($key) {
  33. $mem = gMem();
  34. $res = $mem->delete($key);
  35. return $res;
  36. }
  37. public function testMemSet($key, $value) {
  38. $mem = gMem();
  39. $res = $mem->set($key, $value);
  40. return $res;
  41. }
  42. public function testMemGet($key) {
  43. $mem = gMem();
  44. $res = $mem->get($key);
  45. return $res;
  46. }
  47. public static function dtCurrent() {
  48. $timezone = date_default_timezone_get();
  49. echoLine($timezone . " " . date('Y-m-d H:i:s'));
  50. echoLine("tsweek: " . TimeUtil::tsWeek());
  51. echoLine("tsday: " . TimeUtil::tsDay());
  52. }
  53. //----------------------------------------------------
  54. public static function efficiencyOfOldLog() {
  55. /**
  56. * 测试结果说明,采用写本地文件的性能还是略高于写redis数据库的.
  57. */
  58. for ($i = 0; $i < 1000; $i++) {
  59. CLog::pay("我们的祖国像花园,花园里花朵真鲜艳.和暖的阳光照耀着我们,每个人的脸上都笑开颜.");
  60. }
  61. }
  62. public function testRedisGet($key) {
  63. $mem = gMem();
  64. $ret = $mem->get($key);
  65. DebugHelper:: var_dump($ret);
  66. $mem->close();
  67. return $ret;
  68. }
  69. /**
  70. * 删除某个key
  71. * @param type $key
  72. */
  73. public function testRedisDel($key) {
  74. $mem = gMem();
  75. $num = $mem->delete($key);
  76. echo $num > 0 ? 'ok' : 'not exist';
  77. $mem->close();
  78. }
  79. public function testRedisLua($key, $value) {
  80. $mem = gMem();
  81. $script = <<<SCR
  82. if redis.call("get",KEYS[1]) == ARGV[1]
  83. then
  84. return redis.call("del",KEYS[1])
  85. else
  86. return 0
  87. end
  88. SCR;
  89. DebugHelper:: var_dump($script);
  90. $ret = $mem->redis->eval($script, 1, $key, $value);
  91. DebugHelper:: var_dump($ret);
  92. $mem->close();
  93. }
  94. public function testBinSearch($v) {
  95. $arr = array(1, 2, 3, 4, 4, 11, 12, 124);
  96. $start = 0;
  97. $end = count($arr) - 1;
  98. while ($start <= $end) {
  99. $index = intval(($start + $end) / 2);
  100. if ($v < $arr[$index]) {
  101. $end = $index - 1;
  102. } elseif ($v > $arr[$index]) {
  103. $start = $index + 1;
  104. } else {
  105. echo($index);
  106. return;
  107. }
  108. }
  109. echo($index);
  110. }
  111. public function tsetIp() {
  112. DebugHelper::debug(HttpUtil::getClientEP());
  113. }
  114. public function testLogfile() {
  115. CLog::warn("日志测试", 'log');
  116. }
  117. public static function testDecodeToken($token) {
  118. echoLine("中文显示");
  119. $activeCode = CipheredBase32::Decode($token); # 解码
  120. var_dump($activeCode);
  121. $codePlatStr = GameConstants::GetPlatStringByActivteCode($activeCode); # platstr
  122. var_dump($codePlatStr);
  123. }
  124. }