Ron*_*ero 29 php ram bandwidth cpu-usage system-information
VBulletin如何在不使用的情况下获取系统信息exec
?在没有exec的情况下,我可以获得有关服务器的任何其他信息吗?我对感兴趣:
sha*_*mar 44
使用PHPSysInfo库
phpSysInfo是一个开源PHP脚本,显示有关被访问主机的信息.它将显示如下内容:
它直接解析解析/proc
而不使用exec
.
另一种方法是使用Linfo.它是一个非常快速的跨平台 PHP脚本,它极其详细地描述了主机服务器,提供了诸如ram使用,磁盘空间,raid数组,硬件,网卡,内核,操作系统,samba/cups/truecrypt状态,temps等信息,磁盘等等.
这就是我在Linux服务器上使用的。它仍然使用exec
,但是其他问题在这里指出是重复的,对于这些问题没有[好的]建议。它应该可以在每个发行版上使用,但是如果不行,请尝试使用$get_cores + 1
offset。
CPU使用的核心百分比(平均5分钟):
$exec_loads = sys_getloadavg();
$exec_cores = trim(shell_exec("grep -P '^processor' /proc/cpuinfo|wc -l"));
$cpu = round($exec_loads[1]/($exec_cores + 1)*100, 0) . '%';
Run Code Online (Sandbox Code Playgroud)
RAM占总使用量的百分比(实时):
$exec_free = explode("\n", trim(shell_exec('free')));
$get_mem = preg_split("/[\s]+/", $exec_free[1]);
$mem = round($get_mem[2]/$get_mem[1]*100, 0) . '%';
Run Code Online (Sandbox Code Playgroud)
使用的GB的RAM(实时):
$exec_free = explode("\n", trim(shell_exec('free')));
$get_mem = preg_split("/[\s]+/", $exec_free[1]);
$mem = number_format(round($get_mem[2]/1024/1024, 2), 2) . '/' . number_format(round($get_mem[1]/1024/1024, 2), 2);
Run Code Online (Sandbox Code Playgroud)
$get_mem
如果需要计算其他方面,这是数组中的内容:
[0]=>row_title [1]=>mem_total [2]=>mem_used [3]=>mem_free [4]=>mem_shared [5]=>mem_buffers [6]=>mem_cached
Run Code Online (Sandbox Code Playgroud)
奖金,这是获得正常运行时间的方法:
$exec_uptime = preg_split("/[\s]+/", trim(shell_exec('uptime')));
$uptime = $exec_uptime[2] . ' Days';
Run Code Online (Sandbox Code Playgroud)