Whoo Posted August 7, 2010 Share Posted August 7, 2010 I've been looking for a simple script that would connect to a game server to see if it is still online. I've found many, but not one of them work. They will permanently send back the text "Online", or "Offline". This is the simplest code I have found: <?php $ip = "66.79.190.40"; $port = "27960"; if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) echo '<B><FONT COLOR=red>Offline</b></FONT>'; else{ echo '<B><FONT COLOR=lime>Online</b></FONT>'; fclose($sock); } ?> I'm also looking into getting it to pull the map name and player-list, but I should be able to figure that out on my own once I get this working. If it helps, this script is supposed to connect to the original Quake games(One, two, and three). Quote Link to comment https://forums.phpfreaks.com/topic/210031-script-to-check-if-a-game-server-is-online/ Share on other sites More sharing options...
ChemicalBliss Posted August 7, 2010 Share Posted August 7, 2010 What is the error? <?php $ip = "66.79.190.40"; $port = "27960"; if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) echo '<B><FONT COLOR=red>Offline</b></FONT>'; echo '<br />'.$num.'<br />'.$error; else{ echo '<B><FONT COLOR=lime>Online</b></FONT>'; fclose($sock); } ?> -cb- Quote Link to comment https://forums.phpfreaks.com/topic/210031-script-to-check-if-a-game-server-is-online/#findComment-1096228 Share on other sites More sharing options...
jcbones Posted August 7, 2010 Share Posted August 7, 2010 $sock = @fsockopen($ip, $port, $num, $error, 5) //<-- Remove last argument, Letting it run the default timeout until you are sure your getting a connection. Then adjust. Quote Link to comment https://forums.phpfreaks.com/topic/210031-script-to-check-if-a-game-server-is-online/#findComment-1096246 Share on other sites More sharing options...
PradeepKr Posted August 7, 2010 Share Posted August 7, 2010 If you want to check whether a file is online (a URL is available on the web) then here a few different ways are described to http://www.expertsguide.info/2010/07/how-to-know-if-file-exists-on-web/. Have a look at them. Hope it helps. Quote Link to comment https://forums.phpfreaks.com/topic/210031-script-to-check-if-a-game-server-is-online/#findComment-1096410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.