New file |
| | |
| | | <?php |
| | | include_once "/Common/Logging.php"; |
| | | include_once "/Common/CommFunc.php"; |
| | | include_once "/Account/User.php"; |
| | | include_once '/db/RedisOper.php'; |
| | | |
| | | \Logging\CreateLogging("chatmonitorserver2.php"); |
| | | \Logging\LogInfo("_POST:" . print_r($_POST, true)); |
| | | $spid = $_POST["spid"]; |
| | | |
| | | $interfaceConfig = parse_ini_file("/InterfaceConfig.php", true); |
| | | $GameName = $interfaceConfig["ServerInfo"]["GameName"]; |
| | | $CacheChatCount = $interfaceConfig["Chatmonitor"]["CacheChatCount"]; |
| | | |
| | | $redisKey = \RedisOper\GetFCRedisKey($GameName, "Chatmonitor", $spid); |
| | | |
| | | $retArray = array(); |
| | | if ($_POST["AccountID"]) { |
| | | $chat["Time"]; |
| | | $doCountMax = 12; // 执行取数据次数 |
| | | $perCountSleep = 5; // 每次执行后休眠x秒 |
| | | $sleepTime = $doCountMax * $perCountSleep; |
| | | if ($sleepTime >= 30) { |
| | | set_time_limit($sleepTime + 30); // 限制执行时长秒 30秒 + 休眠时长 |
| | | } |
| | | |
| | | // 直到取到有新数据 |
| | | $doCount = 0; |
| | | while ($doCount < $doCountMax && count($retArray) <= 0) { |
| | | $doCount += 1; |
| | | if ($doCount > 1) { |
| | | sleep($perCountSleep); |
| | | } |
| | | // 取最后一条之后的数据 |
| | | $startIndex = 0; |
| | | $stopIndex = -1; |
| | | $perGetCount = 10; // 每次一次性取几条数据 |
| | | $loopCount = $CacheChatCount / $perGetCount; |
| | | // \Logging\LogInfo("doCount:" . $doCount . " CacheChatCount :" . $CacheChatCount . " loopCount:" . $loopCount); |
| | | $isEnd = false; |
| | | while (!$isEnd && $loopCount >= 0) { |
| | | $loopCount -= 1; |
| | | $startIndex -= $perGetCount; |
| | | // \Logging\LogInfo("i :" . $i . " index:" . $startIndex . " ~ " . $stopIndex); |
| | | // 从后往前读 |
| | | if (!\RedisOper\ListRange($redisKey, $ret, $startIndex, $stopIndex)) { |
| | | break; |
| | | } |
| | | if (isset($ret) && count($ret) > 0) { |
| | | // \Logging\LogInfo("retCount:" . count($ret)); |
| | | // 倒序遍历 |
| | | for ($j = count($ret) - 1; $j >= 0; $j--) { |
| | | $chat = $ret[$j]; |
| | | if ($chat["Time"] < $_POST["Time"] && $_POST["Time"] && $_POST["Time"] != "undefined") { |
| | | $isEnd = true; |
| | | break; |
| | | } |
| | | if ($chat["AccountID"] == $_POST['AccountID'] && $chat["Time"] == $_POST['Time'] && $chat["Content"] == $_POST['Content']) { |
| | | $isEnd = true; |
| | | break; |
| | | } |
| | | array_splice($retArray, 0, 0, array($chat)); |
| | | // \Logging\LogInfo("array_splice count:" . count($retArray) . print_r($chat, true)); |
| | | } |
| | | } else { |
| | | $isEnd = true; |
| | | } |
| | | $stopIndex = $startIndex - 1; |
| | | } |
| | | } |
| | | } else { |
| | | // 全部 |
| | | if (!\RedisOper\ListRange($redisKey, $retArray, 0, -1)) { |
| | | exit; |
| | | } |
| | | } |
| | | if (!isset($retArray) || count($retArray) <= 0) { |
| | | exit; |
| | | } |
| | | |
| | | $msg = array("MsgType" => "CHAT", "Msg" => $retArray); |
| | | echo json_encode($msg); |