<?php

require ('../includes/config.php');

mysql_connect($db_config['host'], $db_config['user'], $db_config['pass']);
mysql_select_db($db_config['name']);

$data = mysql_query("SELECT `id`,`ip`,`port` FROM `servers`");


while ($row = mysql_fetch_array($data))
  {
  
    $check = @fsockopen($row[ip],$row[port],$ern,$erstr,1);

      if($check)
        {
            $onservers[] = $row[id];
             
        }
       else
        {
          
           $offservers[] = $row[id];
           
        }
   
  
  }

mysql_free_result($data);

$onstr = implode(',',$onservers);
$offstr = implode(',',$offservers);


mysql_query("UPDATE `servers` SET `online_checks` = `online_checks` + 1, `online` = `online` + 1 WHERE `id` IN ('$onstr')");   
mysql_query("UPDATE `servers` SET `online_checks` = `online_checks` + 1 WHERE `id` in ('$offstr')");      


echo "Online :", count($onservers) ," Offline :", count($offservers);


?>
