関数 sys_linux() {
// CPU
if (false === ($str = @file("/proc/cpuinfo"))) false を返します;
$str = implode("", $str);
@preg_match_all("/models+names{0,}:+s{0,}([ws)(@.]+)([rn]+)/s", $str, $model);
@preg_match_all("/caches+sizes{0,}:+s{0,}([d.]+s{0,}[A-Z]+[rn]+)/", $str, $cache);
if (false !== is_array($model[1])) {
$res['cpu']['num'] = sizeof($model[1]);
for($i = 0; $i
$res['cpu']['model'][] = $model[1][$i];
$res['cpu']['cache'][] = $cache[1][$i];
}
if (false !== is_array($res['cpu']['model'])) $res['cpu']['model'] = implode("
", $res[' CPU']['モデル']);
if (false !== is_array($res['cpu']['cache'])) $res['cpu']['cache'] = implode("
", $res[' cpu']['キャッシュ']);
}
// 稼働時間
if (false === ($str = @file("/proc/uptime"))) return false;
$str =explode(" ", implode("", $str));
$str = トリム($str[0]);
$min = $str / 60;
$時間 = $分 / 60;
$days = フロア($hours / 24);
$hours = フロア($hours - ($days * 24));
$min = フロア($min - ($days * 60 * 24) - ($hours * 60));
if ($days !== 0) $res['uptime'] = $days."天";
if ($hours !== 0) $res['uptime'] .= $hours."小時間";
$res['uptime'] .= $min."分钟";
// 記憶
if (false === ($str = @file("/proc/meminfo"))) false を返します;
$str = implode("", $str);
preg_match_all("/MemTotals{0,}:+s{0,}([d.]+).+?MemFrees{0,}:+s{0,}([d.]+).+?SwapTotals{ 0,}:+s{0,}([d.]+).+?SwapFrees{0,}:+s{0,}([d.]+)/s", $str, $buf);
$res['memTotal'] =round($buf[1][0]/1024, 2);
$res['memFree'] =round($buf[2][0]/1024, 2);
$res['memused'] = ($res['memTotal']-$res['memFree']);
$res['memPercent'] = (floatval($res['memTotal'])!=0)?round($res['memused']/$res['memTotal']*100,2):0;
$res['swapTotal'] =round($buf[3][0]/1024, 2);
$res['swapFree'] =round($buf[4][0]/1024, 2);
$res['swapused'] = ($res['swapTotal']-$res['swapFree']);
$res['swapPercent'] = (floatval($res['swapTotal'])!=0)?round($res['swapused']/$res['swapTotal']*100,2):0;
// 平均ロード
if (false === ($str = @file("/proc/loadavg"))) false を返します;
$str =explode(" ", implode("", $str));
$str = array_chunk($str, 4);
$res['loadAvg'] = implode(" ", $str[0]);
$res を返す;}