php linux 运行时间,PHP获取 linux 服务器 运行时间

方法一:<?php

if ( !function_exists( 'sys_uptime' ) ) {

function sys_uptime() {

$output='';

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) $output .= $days."天";

if ($hours !== 0) $output .= $hours."小时";

if ($min !== 0) $output .= $min."分钟";

return $output;

}

}

$starttime = sys_uptime();

echo $starttime;

?>

或者<?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;

?>

方法二:<?php

function Uptime() {

$uptime = @file_get_contents( "/proc/uptime");

$uptime = explode(" ",$uptime);

$uptime = $uptime[0];

$days = explode(".",(($uptime % 31556926) / 86400));

$hours = explode(".",((($uptime % 31556926) % 86400) / 3600));

$minutes = explode(".",(((($uptime % 31556926) % 86400) % 3600) / 60));

$seconds = explode(".",((((($uptime % 31556926) % 86400) % 3600) / 60) / 60));

$time = $days[0].":".$hours[0].":".$minutes[0].":".$seconds[0];

return $time;

}

?>

方法三:<?php

function Uptime() {

$str = @file_get_contents('/proc/uptime');

$num = floatval($str);

$secs = $num % 60;

$num = (int)($num / 60);

$mins = $num % 60;

$num = (int)($num / 60);

$hours = $num % 24;

$num = (int)($num / 24);

$days = $num;

return array(

"days" => $days,

"hours" => $hours,

"mins" => $mins,

"secs" => $secs

);

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值