【问题标题】:Make loops in php在php中创建循环
【发布时间】:2016-08-30 22:23:05
【问题描述】:

我其实是在做一个脚本来检查游戏服务器是在线还是离线!

到目前为止,我制作的脚本不会每 20 分钟检查一次服务器。 我希望脚本检查服务器是在线还是离线并输出信息。

我现在的代码是:

/* 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';

}

您能告诉我如何每 20 分钟执行一次相同的脚本并输出信息吗?

提前致谢

【问题讨论】:

  • 您只想刷新浏览器吗?
  • 不,我不希望浏览器刷新。我希望脚本每 20 分钟执行一次并输出结果@Quasimodo'sclone
  • 你想把结果输出到哪里?在网页中?或者在一个文件中。 cron Jobs 不允许您查看网页中的输出。但是您可以在设置 cronjob 时将输出写入文件..
  • @RossiMilanBob Milan Bob 好吧,请查看这个网站。我希望我的脚本每 20 分钟检查一次服务器状态。 coc-servers.com

标签: php fsockopen json-api


【解决方案1】:

我认为,您将需要一个 cron 作业。

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

Cron 实际上在服务器上以给定的时间间隔执行指定的文件。

【讨论】:

猜你喜欢
  • 2014-06-19
  • 1970-01-01
  • 1970-01-01
  • 2015-02-23
  • 2012-03-18
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多