Changeset 8 for scripts/online.php
- Timestamp:
- Jun 5, 2008, 9:38:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
scripts/online.php
r7 r8 1 1 <?php 2 3 // Script executed by cron every 5 minutes 2 4 3 5 include('../includes/config.php'); … … 34 36 { 35 37 echo($Server['name'].' - '); 38 $MeasureStart = microtime(TRUE); 36 39 $OnlineState = CheckPortStatus($Server['ip'], $Server['port']); 40 $Latency = (microtime(TRUE) - $MeasureStart) * 1000; 37 41 $OnlineCount += $OnlineState; 38 42 $OfflineCount += 1 - $OnlineState; 39 43 // 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.")"); 41 45 42 46 // Delete old records 43 $Database->query("DELETE FROM `servers_online` WHERE `server` = ".$Server['id']." AND time < DATE_SUB(NOW(), INTERVAL 1DAY)");47 $Database->query("DELETE FROM `servers_online` WHERE `server` = ".$Server['id']." AND time < DATE_SUB(NOW(), INTERVAL ".$Config['OnlineStatePeriodLength']." DAY)"); 44 48 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 45 55 // Calculate cached percentage online state 46 56 $DbResult = $Database->query("SELECT COUNT(*) as `count`, SUM(`state`) as `online` FROM `servers_online` WHERE `server` = ".$Server['id']); 47 57 $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']); 49 61 $DbResult->free(); 50 62 echo($TextState[$OnlineState]."<br>\n");
Note:
See TracChangeset
for help on using the changeset viewer.