红联Linux门户
Linux帮助

php获取Linux系统运行时间

发布时间:2014-07-30 10:33:19来源:linux网站作者:luxiaok

php获取Linux系统运行时间代码:


<?php
function sys_linux()
{
if (false === ($str = @file("/proc/uptime"))) return false;
$str = explode(" ", implode("", $str));
$str = trim($str[0]);
$min = $str / 60;
$hours = $min / 60;
$days = floor($hours / 24);
$hours = floor($hours - ($days * 24));
$min = floor($min - ($days * 60 * 24) - ($hours * 60));
if ($days !== 0) $res['uptime'] = $days."天";
if ($hours !== 0) $res['uptime'] .= $hours."小时";
$res['uptime'] .= $min."分钟";
return$res;
}
$sysInfo = sys_linux();
$uptime = $sysInfo['uptime'];
echo$uptime;
?>


效果可以自己测试下,不传图片了。