Witam! Mam taki oto prosty skrypt, który ma sprawdzać status serwera, i pobierać z niego dane (Uptime, gracze online):
$info = chr(6).chr(0).chr(255).chr(255).'info';
$sock = fsockopen('localhost', 7171
, $errno, $errstr, 1
);
//show source request
if($_REQUEST['action']=='source'){
}
else{
if ($sock)
{
//writes the info gotten by sending the server packet.
$data='';
{
$data .= fgets($sock, 1024
); }
//players online and max (ex. Players online: 24 / 100)
preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches); echo '<br />Players: '.$matches[1].' / '.$matches[2
];
//Monster total (ex. Monsters: 23456)
preg_match('/monsters total="(\d+)"/', $data, $matches); print '<br />Monsters: '.$matches[1].'';
//Uptime (Uptime: 23h 12m)
$h = floor($matches[1
] / 3600
); $m = floor(($matches[1
] - $h*3600
) / 60
);
echo '<br />Uptime: '.$h.'h '.$m.'m'.'</p>'; <ul>
</ul>';
}
else
{
}
}
jest to skrypt do OTSa (otwartego serwera tibii). Błąd polega na tym, że czasami wyświetla dane normalnie:
on
Players: 2/1000
Monsters: 2001
Uptime: 3h 30m
a czasami poprostu takie cos:
on
Players: /
Monsters:
Uptime: 0h 0m