Changeset 8 for scripts/online.php


Ignore:
Timestamp:
Jun 5, 2008, 9:38:23 PM (17 years ago)
Author:
george
Message:

Přidáno: Zaznamenávání a zobrazování údaje o odezevně serverů.
Upraveno: Šablony stránek a použití jazykových proměnných ve větší míře.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/online.php

    r7 r8  
    11<?php
     2
     3// Script executed by cron every 5 minutes
    24
    35include('../includes/config.php');
     
    3436{
    3537  echo($Server['name'].' - ');
     38  $MeasureStart = microtime(TRUE);
    3639  $OnlineState = CheckPortStatus($Server['ip'], $Server['port']);
     40  $Latency = (microtime(TRUE) - $MeasureStart) * 1000;
    3741  $OnlineCount += $OnlineState;
    3842  $OfflineCount += 1 - $OnlineState;
    3943  // Insert new online state
    40   $Database->query("INSERT INTO `servers_online` (`server` ,`time` ,`state` ,`players_count`) VALUES (".$Server['id'].", NOW() , ".$OnlineState.", ".$PlayersCount.")");
     44  $Database->query("INSERT INTO `servers_online` (`server`, `time`, `state`, `players_count`, `latency`) VALUES (".$Server['id'].", NOW() , ".$OnlineState.", ".$PlayersCount.", ".$Latency.")");
    4145
    4246  // Delete old records
    43   $Database->query("DELETE FROM `servers_online` WHERE `server` = ".$Server['id']." AND time < DATE_SUB(NOW(), INTERVAL 1 DAY)");
     47  $Database->query("DELETE FROM `servers_online` WHERE `server` = ".$Server['id']." AND time < DATE_SUB(NOW(), INTERVAL ".$Config['OnlineStatePeriodLength']." DAY)");
    4448 
     49  // Calculate latency average
     50  $DbResult = $Database->query("SELECT AVG(`latency`) as `latency` FROM `servers_online` WHERE `server` = ".$Server['id']." AND `state` = 1 AND `latency` != 0");
     51  $DbRow = $DbResult->fetch_array();
     52  $Latency = $DbRow['latency'];
     53  $DbResult->free();
     54
    4555  // Calculate cached percentage online state
    4656  $DbResult = $Database->query("SELECT COUNT(*) as `count`, SUM(`state`) as `online` FROM `servers_online` WHERE `server` = ".$Server['id']);
    4757  $DbRow = $DbResult->fetch_array();
    48   $Database->query("UPDATE `servers` SET `online` = ".round($DbRow['online'] / $DbRow['count'] * 100, 2)." WHERE `id` = ".$Server['id']);
     58
     59  // Update servers info
     60  $Database->query("UPDATE `servers` SET `online` = ".round($DbRow['online'] / $DbRow['count'] * 100, 2).", `latency` = ".$Latency." WHERE `id` = ".$Server['id']);
    4961  $DbResult->free();
    5062  echo($TextState[$OnlineState]."<br>\n");
Note: See TracChangeset for help on using the changeset viewer.