2016-05-05 6 views
2

私は実際にゲームサーバーがオンラインかオフラインかをチェックするスクリプトを作成しています!PHPでループを作成する

現在、20分ごとにサーバーをチェックしていないスクリプトを作成しました。 スクリプトがサーバーがオンラインかオフラインかをチェックして情報を出力したい。

私が今持っているコードです:あなたは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'; 

} 

を教えてくださいことはできますか?

ありがとうございます。

+0

ブラウザを更新するだけですか? –

+0

いいえ、ブラウザを更新したくありません。スクリプトを20分実行して結果を出力します。@ Quasimodo'sclone – karansanjeev

+0

結果はどこに出力しますか?ウェブページで?またはファイルで。 cron Jobsでは、Webページの出力を見ることができません。しかし、あなたはクローンを設定している間に出力をファイルに書き込むことができます。 –

答えて

1

私はそう思うと、あなたはこのためにcronジョブが必要になると思います。

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

cronは実際にサーバ上の指定した間隔で指定したファイルを実行します。

+0

cronジョブの使い方を教えてください。私はcPanelと一緒にいて、私にはロットアクセスはありません。とにかくPHPでそれを行うには? – karansanjeev

+0

Cronジョブは、CPanel(Advanced> Cron Jobs)で利用できます。構文の詳細については、この回答を参照してください:http://stackoverflow.com/questions/7332804/run-a-php-file-in-a-cron-job-using-cpanel – swordsecurity

+0

このcpanel UIも確認してください.. https ://documentation.cpanel.net/display/ALD/Cron+Jobs – Sid

関連する問題