php FreeBSD系统探测程序
function sys_freebsd() {
//CPU
if (false === ($res['cpu']['num'] = get_key("hw.ncpu"))) return false;
$res['cpu']['model'] = get_key("hw.model");
//LOAD AVG
if (false === ($res['loadAvg'] = get_key("vm.loadavg"))) return false;
//UPTIME
if (false === ($buf = get_key("kern.boottime"))) return false;
$buf = explode(' ', $buf);
$sys_ticks = time() - intval($buf[3]);
$min = $sys_ticks / 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."分钟";
//MEMORY
if (false === ($buf = get_key("hw.physmem"))) return false;
$res['memTotal'] = round($buf/1024/1024, 2);
$buf = explode("n", do_command("vmstat", ""));
$buf = explode(" ", trim($buf[2]));
$res['memFree'] = round($buf[5]/1024, 2);
$res['memUsed'] = ($res['memTotal']-$res['memFree']);
$res['memPercent'] = (floatval($res['memTotal'])!=0)?round($res['memUsed']/$res['memTotal']*100,2):0;
$buf = explode("n", do_command("swapinfo", "-k"));
$buf = $buf[1];
preg_match_all("/([0-9]+)s+([0-9]+)s+([0-9]+)/", $buf, $bufArr);
$res['swapTotal'] = round($bufArr[1][0]/1024, 2);
$res['swapUsed'] = round($bufArr[2][0]/1024, 2);
$res['swapFree'] = round($bufArr[3][0]/1024, 2);
$res['swapPercent'] = (floatval($res['swapTotal'])!=0)?round($res['swapUsed']/$res['swapTotal']*100,2):0;
return $res;
}
//取得参数值 FreeBSD
function get_key($keyName) {
return do_command('sysctl', "-n $keyName");
}
//确定执行文件位置 FreeBSD
function find_command($commandName) {
$path = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
foreach($path as $p) {
if (@is_executable("$p/$commandName")) return "$p/$commandName";
}
return false;
}
//执行系统命令 FreeBSD
function do_command($commandName, $args) {
$buffer = "";
if (false === ($command = find_command($commandName))) return false;
if ($fp = @popen("$command $args", 'r')) {
while (!@feof($fp)){
$buffer .= @fgets($fp, 4096);
}
return trim($buffer);
}
return false;
}
教程网址:
欢迎收藏∩_∩但请保留本文链接。
推荐阅读
-
Debian系统下为PHP程序配置Nginx服务器的基本教程
-
PHP系统流量分析的程序
-
PHP 一键安装扩展的程序-(Windows 系统)
-
freebsd6.2 nginx+php+mysql+zend系统优化防止ddos攻击
-
Debian系统下为PHP程序配置Nginx服务器的基本教程
-
ubuntu系统,在终端命令行,有什么下令,可以编辑PHP程序
-
ubuntu系统,在终端命令行调试PHP程序,有什么软件?
-
这是我在做的一个系统中的新闻增加程序,可以上传图片,也可以输_PHP
-
ubuntu系统,在终端命令行调试PHP程序,有什么软件?解决方法
-
PHP程序不适用大型系统的九大原因_PHP教程