serverStat(); } private function serverStat() { $serverLogs = ServerLog::select( 'server_id', DB::raw("sum(u) as u"), DB::raw("sum(d) as d"), DB::raw("count(*) as online") ) ->where('updated_at', '>=', time() - 3600) ->groupBy('server_id') ->get(); foreach ($serverLogs as $serverLog) { $data = [ 'server_id' => $serverLog->server_id, 'u' => $serverLog->u, 'd' => $serverLog->d, 'online' => $serverLog->online ]; dd(Cache::put(CacheKey::get('SERVER_STAT', $serverLog->server_id), json_encode($data), 3600)); ServerStat::create($data); } } }