Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Linux System Last Boot Time

Tags:

linux

php

centos

From a PHP script I need to get the last system boot time, preferably in the UNIX time stamp format.

Are there any files that are created or modified at boot time? I could read the modified time of the file.

The system type is CentOS.

like image 211
Drahcir Avatar asked Dec 19 '25 09:12

Drahcir


1 Answers

/proc/uptime

This file contains two numbers: the uptime of the system (seconds), and the amount of time spent in idle process (seconds).

<?php

function get_boottime() {
    $tmp = explode(' ', file_get_contents('/proc/uptime'));

    return time() - intval($tmp[0]);
}

echo get_boottime() . "\n";
like image 174
clyfish Avatar answered Dec 21 '25 00:12

clyfish