2

I am actually making a script to check whether game server is online or offline!

As of now the script i have made which does not check the server every 20 minutes. I want the script to check whether the server is online or offline and out put the information.

The code i have now is :

/* Server Information
–––––––––––––––––––––––––––––––––––––––––––––––––– */

$server_Debug = "9332";
$server_Port = "9339";
$server_key = "UCSGL"; 

/* Get's IP
–––––––––––––––––––––––––––––––––––––––––––––––––– */

$server_Ip = file_get_contents('http://bot.whatismyipaddress.com/');

/* API installation
–––––––––––––––––––––––––––––––––––––––––––––––––– */

 if ($isOnline = @fsockopen($server_Ip,$server_Port,$errno,$errstr)) {
  fclose($isOnline);  //Establish connection to api if server online

    $serverStatus = '<div class="callout callout-success"><h4>Server Online!</h4><p>Server is online, you can start playing with us!</div>';
    $memClans = file_get_contents("http://$server_Ip:$server_Debug/$server_key/inmemclans");
    $onPlayers = file_get_contents("http://$server_Ip:$server_Debug/$server_key/onlineplayers");
    $players = file_get_contents("http://$server_Ip:$server_Debug/$server_key/totalclients");
    $usedram = file_get_contents("http://$server_Ip:$server_Debug/$server_key/ram");
    $info = '<i class="fa fa-circle text-success"></i> Online';


} else {  //Else display N/A instead if throwing 404 and reuining the page!

    $serverStatus = '<div class="callout callout-danger"><h4>Server Offline!</h4><p>Server is Offline, we are working on to fix it! Will start to work soon.</p></div>';
    $memClans = "N/A";
    $onPlayers = "N/A";
    $players = "N/A";
    $usedram = "N/A";
    $info = '<i class="fa fa-circle text-danger"></i> Offline';

}

Can you please tell me how to execute this same script every 20 minutes and output the information?

Thanks in advance

  • Do you want nothing more than a browser refresh? – Pinke Helga May 05 '16 at 08:02
  • No, i don't want the browser to refresh. I want the script to execute itself ever 20 min and output the result @Quasimodo'sclone – karansanjeev May 05 '16 at 09:17
  • Where do you want to output the result? In the webpage? Or in a file. The cron Jobs doesn't allow you to see the outputs in webpages. But you can write the outputs to a file while setting the cronjob.. – Sabin Chacko May 05 '16 at 09:23
  • @RossiMilanBob Milan Bob Well, please check out this website. I want my script to check the server status every 20 minutes. https://www.coc-servers.com/ – karansanjeev May 05 '16 at 09:42

1 Answers1

1

I think, you will need a cron job for this.

https://en.wikipedia.org/wiki/Cron

Cron actually executes a specified file at given interval on server.

Sid
  • 560
  • 7
  • 17