Changeset 5 for scripts/online.php
- Timestamp:
- Jun 4, 2008, 7:35:37 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
scripts/online.php
r1 r5 6 6 mysql_select_db($db_config['name']); 7 7 8 $data = mysql_query("SELECT `id`,`ip`,`port` FROM `servers`"); 8 function CheckPortStatus($Ip, $Port) 9 { 10 $Timeout = 1; 11 if($Socket = @fsockopen($Ip, $Port, $ErrorNumber, $ErrorString, $Timeout)) 12 { 13 fclose($Socket); 14 return(true); 15 } else 16 { 17 return(false); 18 } 19 } 9 20 21 echo("Kontroluji stav serveru...<br>\n"); 22 $OnlineCount = 0; 23 $OfflineCount = 0; 24 $Servers = mysql_query("SELECT `id`,`ip`,`port`,`name` FROM `servers`"); 25 while($Server = mysql_fetch_array($Servers)) 26 { 27 echo($Server['name'].' - '); 28 if(CheckPortStatus($Server['ip'], $Server['port'])) 29 { 30 mysql_query("UPDATE `servers` SET `online_checks` = `online_checks` + 1, `online` = `online` + 1 WHERE `id`=".$Server['id']); 31 echo('Online'); 32 $OnlineCount++; 33 } else 34 { 35 mysql_query("UPDATE `servers` SET `online_checks` = `online_checks` + 1 WHERE `id` =".$Server['id']); 36 echo('Offline'); 37 $OfflineCount++; 38 } 39 echo("<br>\n"); 40 } 41 mysql_free_result($Servers); 10 42 11 while ($row = mysql_fetch_array($data)) 12 { 13 14 $check = @fsockopen($row[ip],$row[port],$ern,$erstr,1); 15 16 if($check) 17 { 18 $onservers[] = $row[id]; 19 20 } 21 else 22 { 23 24 $offservers[] = $row[id]; 25 26 } 27 28 29 } 30 31 mysql_free_result($data); 32 33 $onstr = implode(',',$onservers); 34 $offstr = implode(',',$offservers); 35 36 37 mysql_query("UPDATE `servers` SET `online_checks` = `online_checks` + 1, `online` = `online` + 1 WHERE `id` IN ('$onstr')"); 38 mysql_query("UPDATE `servers` SET `online_checks` = `online_checks` + 1 WHERE `id` in ('$offstr')"); 39 40 41 echo "Online :", count($onservers) ," Offline :", count($offservers); 42 43 echo('Total: '.($OnlineCount + $OfflineCount).', Online: '.$OnlineCount.', Offline: '.$OfflineCount."<br>\n"); 43 44 44 45 ?>
Note:
See TracChangeset
for help on using the changeset viewer.