質問

I am trying to create a system to monitor a Minecraft server using PHP. It will then periodically(every 10 minutes) check the status of the server. If the server is unreachable, it will time for how long it went down and then store that in a database.

I have created the code to check the server status but am struggling with timing for how long the server went off. What ways could I time the downtime ?

役に立ちましたか?

解決

You cant calculate the downtime, I suggest that when a downtime is occured, you check it again in every one minute until the uptime, and get the difference of first down time and next uptime, this gives you a downtime with accuracy of one minute

他のヒント

you can update to the database the last up-time and calculate downtime with it and overwrite the downtime every time you calculate it

For this type of tasks, crontab is a great tool: it's a file that will execute defined commands at the time you set them.

you can use your isp's cpanel tool named cron jobs. from there it's pretty easy to create a cron job. just enter the command portion of the three lines below.

if you can't use this tool or prefer to write directly into your crontab, those lines are the resultant command (from http://www.pantz.org/software/cron/croninfo.html):

# Minute          Hour   Day of Month       Month          Day of Week        Command    
# (0-59)          (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)                
0,10,20,30,40,50        *          *             *                *            php /home/yourdomain/public_html/test.php

my test.php:

mail('mail@internets.com','time();',date('H:i:s',time()));

this mails the time each ten minutes. from there on you patch your status checker code in test.php (or whatever name you want) and insert this data in database. I don't have enough information to provide code to calculate time. What is your data structure? How do you interact with your database?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top