PHP 如何獲取Linux 服務器的uptime
下面兩種PHP 方法都可以獲取Linux 服務器的uptime:
<?php
$uptime = trim(shell_exec('uptime'));
// output is 04:47:32 up 187 days, 5:03, 1 user, load average: 0.55, 0.55, 0.54
$uptime = explode(',', $uptime);
$uptime = explode(' ', $uptime[0]);
$uptime = $uptime[2].' '.$uptime[3]; // 187 days
?>
<?php
$uptime = trim(file_get_contents('/proc/uptime'));
$uptime = explode(' ', $uptime);
echo $uptime[0]; //uptime in seconds
?>