final60 Posted January 4, 2009 Share Posted January 4, 2009 Hey guys Id like to be able to track the uptime of a server, the main features i'd like are: Primarily to track in real time the last time server was reset and how long the server has been up since last reset! It might appear like this: Last Reset: 12th Dec 2008 at 23h:11m:24s Uptime: 00:00:04h:14m:11s Additionally i'd also like to log when the server is restarted in a basic text file if possible. The server IP is : ari1.ryzom.com If anyone can suggest where to start I'd greatly appreciate. Quote Link to comment https://forums.phpfreaks.com/topic/139437-aplication-logging-server-uptime/ Share on other sites More sharing options...
DarkWater Posted January 4, 2009 Share Posted January 4, 2009 The unix uptime utility can give you the uptime, so then you can easily calculate the last reset. You can access that program in PHP using exec() (or another one in the exec() family), or backticks: <?php $uptime = `uptime`; ?> Quote Link to comment https://forums.phpfreaks.com/topic/139437-aplication-logging-server-uptime/#findComment-729410 Share on other sites More sharing options...
premiso Posted January 4, 2009 Share Posted January 4, 2009 <?php $data = shell_exec('uptime'); $uptime = explode(' up ', $data); $uptime = explode(',', $uptime[1]); $uptime = $uptime[0].', '.$uptime[1]; echo 'Uptime: '.$uptime; ?> Not sure if this works on windows, but yea. To get the last reset time you just take the uptime convert it to seconds and subtract it from the current timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/139437-aplication-logging-server-uptime/#findComment-729413 Share on other sites More sharing options...
DarkWater Posted January 4, 2009 Share Posted January 4, 2009 My scan shows that he's got some sort of Linux running, so it should be fine. Quote Link to comment https://forums.phpfreaks.com/topic/139437-aplication-logging-server-uptime/#findComment-729416 Share on other sites More sharing options...
final60 Posted January 4, 2009 Author Share Posted January 4, 2009 <?php $data = shell_exec('uptime'); $uptime = explode(' up ', $data); $uptime = explode(',', $uptime[1]); $uptime = $uptime[0].', '.$uptime[1]; echo 'Uptime: '.$uptime; ?> Not sure if this works on windows, but yea. To get the last reset time you just take the uptime convert it to seconds and subtract it from the current timestamp. Thanks alot for your suggestions. Im very much a php nublet. How do I apply the above markup to the server ip address: ari1.ryzom.com? Quote Link to comment https://forums.phpfreaks.com/topic/139437-aplication-logging-server-uptime/#findComment-729451 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.