Display your server uptime on your website

If you host your own server and website like myself, you'll probably want to distplay your current uptime somewhere on your site. You are in luck, it is easy....

It uses the Linux command uptime and strips the unecessary gubbins from the output string:

$ uptime

This results contains some useful info including number of users logged on and loads as well as the uptime:

18:10:45 up 39 days, 22:04,  1 user,  load average: 0.07, 0.06, 0.08

All you have to do is to insert the following php code into your page and you are away.

$data = shell_exec('uptime'); 
$first = strpos($data, 'up'); 
$data = substr($data,$first); 
$first = strpos($data, ','); 
$data = substr($data,0,$first); 
$data = str_replace('up','Powered by Raspberry Pi, ',$data); 
echo $data . ' uptime'

You can see the results from my site at the footer of the page.

Powered by Raspberry Pi, 39 days uptime

Tags : uptime data RPI

Share page

Subscribe to newsletter

Search Posts

Back to top