VBulletin如何在不使用的情况下获取系统信息exec?在没有 exec 的情况下,我还能获得关于服务器的任何其他信息吗?我对感兴趣:
- 使用的带宽
 - 系统类型
 - CPU 速度/使用率/计数
 - 内存使用情况
 
VBulletin如何在不使用的情况下获取系统信息exec?在没有 exec 的情况下,我还能获得关于服务器的任何其他信息吗?我对感兴趣:
使用PHPSysInfo库
phpSysInfo 是一个开放源代码的 PHP 脚本,它显示有关正在访问的主机的信息。它将显示如下内容:
它直接解析解析/proc而不使用exec.
另一种方法是使用Linfo。它是一个非常快速的跨平台php 脚本,可以极其详细地描述主机服务器,提供诸如内存使用、磁盘空间、RAID 阵列、硬件、网卡、内核、操作系统、samba/cups/truecrypt 状态、临时、磁盘等等。
这是我在 Linux 服务器上使用的。它仍然使用exec,但其他问题在这里指向重复,并且没有[好的]建议。它应该适用于每个发行版,但如果没有,请尝试使用$get_cores + 1偏移量。
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) . '%';
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) . '%';
使用的 RAM(以 GB 为单位)(实时):
$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);
$get_mem如果您需要计算其他方面,这是数组中的内容:
[0]=>row_title [1]=>mem_total [2]=>mem_used [3]=>mem_free [4]=>mem_shared [5]=>mem_buffers [6]=>mem_cached
奖金,这是如何获得正常运行时间:
$exec_uptime = preg_split("/[\s]+/", trim(shell_exec('uptime')));
$uptime = $exec_uptime[2] . ' Days';
    <?php
function get_server_load() 
{
    $load=array();
    if (stristr(PHP_OS, 'win')) 
    {
        $wmi = new COM("Winmgmts://");
        $server = $wmi->execquery("SELECT LoadPercentage FROM Win32_Processor");  
        $cpu_num = 0;
        $load_total = 0;
        foreach($server as $cpu)
        {
            $cpu_num++;
            $load_total += $cpu->loadpercentage;
        }
        $load[]= round($load_total/$cpu_num);
    } 
    else
    {
        $load = sys_getloadavg();
    }
    return $load;
}
echo implode(' ',get_server_load());
    这就是我用于即时 CPU 使用的方法,没有 1 秒延迟
$cpu = shell_exec('top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk \'{print 100 - $1}\'');
    在论坛上搜索并尝试了多种方法后,最准确的是:
$stat1 = file('/proc/stat'); 
sleep(1); 
$stat2 = file('/proc/stat'); 
$info1 = explode(" ", preg_replace("!cpu +!", "", $stat1[0])); 
$info2 = explode(" ", preg_replace("!cpu +!", "", $stat2[0])); 
$dif = array(); 
$dif['user'] = $info2[0] - $info1[0]; 
$dif['nice'] = $info2[1] - $info1[1]; 
$dif['sys'] = $info2[2] - $info1[2]; 
$dif['idle'] = $info2[3] - $info1[3]; 
$total = array_sum($dif); 
$cpu = array(); 
foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 1);
print_r($cpu);