where(['node' => $node])->field("title")->find(); if ($nodeName) { $nodeName = $nodeName['title']; } $data = [ 'ip' => $ip, 'node' => $node, 'node_name' => $nodeName, 'action' => $action, 'action_name' => $actionName, 'action_id' => $actionId, 'content' => $content, 'module' => $module, 'from' => $from, 'user_agent' => $header['user-agent'], 'seconds' => time(), ]; return self::db()->insert($data) !== false; } /** * 流控策略 * @param $node * @param string $ip * @throws \Exception */ public static function checkTraffic($node, $ip = '') { $where = ['node' => $node, 'seconds' => time()]; if ($ip) { $where['ip'] = $ip; } $count = self::db()->where($where)->count(); if ($count >= 10) { throw new \Exception('访问过于频繁', 1); } } }