获取Linux系统上次启动时间

Dra*_*cir 1 php linux centos

从PHP脚本我需要获得最后的系统启动时间,最好是UNIX时间戳格式.

是否有任何在启动时创建或修改的文件?我可以读取文件的修改时间.

系统类型是CentOS.

cly*_*ish 7

的/ proc /运行时间

此文件包含两个数字:系统的正常运行时间(秒)以及空闲进程所花费的时间(秒).

<?php

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

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

echo get_boottime() . "\n";
Run Code Online (Sandbox Code Playgroud)