I would like to create check online status for gameserver so is there any kind of way to do that?
Printable View
I would like to create check online status for gameserver so is there any kind of way to do that?
If you know which port the gameserver is running on, you could use fsockopen to check whether it is up or not.
I already used this, but i don't get right answer.
(Let's play that mysql is my gameserver now.)
MySQL as turned off.PHP Code:<?php
$Get = fsockopen("127.0.0.1", "3306", $ErrorNo, $ErrorSTR, 5);
if($Get) {
echo "Online";
}
else {
echo "Offline";
}
?>
MySQL as turned on.Quote:
Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:3306 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\AppServ\www\index.php on line 9
Offline
How do i can filter this: "Warning" message from offline mode to only "Offline".Quote:
Online
Still using same code. Just took MySQL for example.
you could turn off warnings using error_reporting().
hey Zeuz this code doesn't show the errors if the warnings are on... by the way, the warnings are good to have on.
Code:<?php
$host = "192.168.1.15"; // ip or domain
$port = "80";
@$socket = fsockopen($host, $port, $errno, $errstr, 5);
if(!$socket) {
echo "Offline";
} else {
fclose($socket);
echo "Online";
}
?>
Oh. I try this later Justa.