src/Koldy/Server.php
public static function getServerLoad(): string
    {
        if (function_exists('sys_getloadavg')) {
            $a = sys_getloadavg();
            foreach ($a as $k => $v) {
                $a[$k] = round($v, 2);
            }
            return implode(', ', $a);
        } else {
            $os = strtolower(PHP_OS);
            if (strpos($os, 'win') === false) {
                if (@file_exists('/proc/loadavg') && @is_readable('/proc/loadavg')) {
                    $load = file_get_contents('/proc/loadavg');
                    $load = explode(' ', $load);
                    return implode(',', $load);
                } else if (function_exists('shell_exec')) {
                    $load = @shell_exec('uptime');
                    $load = explode('load average' . (PHP_OS == 'Darwin' ? 's' : '') . ':', $load);
                    return implode(',', $load);
                    //return $load[count($load)-1];
                } else {
                    throw new Exception('Unable to get server load');
                }
            } else if (class_exists('COM')) {
                $wmi = new \COM("WinMgmts:\\\\.");
                $CPUs = $wmi->InstancesOf('Win32_Processor');

                $cpuLoad = 0;
                $i = 0;

                while ($cpu = $CPUs->Next()) {
                    $cpuLoad += $cpu->LoadPercentage;
                    $i++;
                }

                $cpuLoad = round($cpuLoad / $i, 2);
                return $cpuLoad . '%';
            }
        }

        throw new Exception('Unable to get server load');
    }
public static function getServerLoad(): string
    {
        if (function_exists('sys_getloadavg')) {
            $a = sys_getloadavg();
            foreach ($a as $k => $v) {
                $a[$k] = round($v, 2);
            }
            return implode(', ', $a);
        } else {
            $os = strtolower(PHP_OS);
            if (strpos($os, 'win') === false) {
                if (@file_exists('/proc/loadavg') && @is_readable('/proc/loadavg')) {
                    $load = file_get_contents('/proc/loadavg');
                    $load = explode(' ', $load);
                    return implode(',', $load);
                } else if (function_exists('shell_exec')) {
                    $load = @shell_exec('uptime');
                    $load = explode('load average' . (PHP_OS == 'Darwin' ? 's' : '') . ':', $load);
                    return implode(',', $load);
                    //return $load[count($load)-1];
                } else {
                    throw new Exception('Unable to get server load');
                }
            } else if (class_exists('COM')) {
                $wmi = new \COM("WinMgmts:\\\\.");
                $CPUs = $wmi->InstancesOf('Win32_Processor');

                $cpuLoad = 0;
                $i = 0;

                while ($cpu = $CPUs->Next()) {
                    $cpuLoad += $cpu->LoadPercentage;
                    $i++;
                }

                $cpuLoad = round($cpuLoad / $i, 2);
                return $cpuLoad . '%';
            }
        }

        throw new Exception('Unable to get server load');
    }
public static function getServerLoad ( ) : string { if ( function_exists ( 'sys_getloadavg' ) ) { $ a = sys_getloadavg ( ) ; foreach ( $ a as $ k => $ v ) { $ a [ $ k ] = round ( $ v , 2 ) ; } return implode ( ', ' , $ a ) ; } else { $ os = strtolower ( PHP_OS ) ; if ( strpos ( $ os , 'win' ) === false ) { if ( @ file_exists ( '/proc/loadavg' ) && @ is_readable ( '/proc/loadavg' ) ) { $ load = file_get_contents ( '/proc/loadavg' ) ; $ load = explode ( ' ' , $ load ) ; return implode ( ',' , $ load ) ; } else if ( function_exists ( 'shell_exec' ) ) { $ load = @ shell_exec ( 'uptime' ) ; $ load = explode ( 'load average' . ( PHP_OS == 'Darwin' ? 's' : '' ) . ':' , $ load ) ; return implode ( ',' , $ load ) ; //return $load[count($load)-1]; } else { throw new Exception ( 'Unable to get server load' ) ; } } else if ( class_exists ( 'COM' ) ) { $ wmi = new \ COM ( "WinMgmts:\\\\." ) ; $ CPUs = $ wmi -> InstancesOf ( 'Win32_Processor' ) ; $ cpuLoad = 0 ; $ i = 0 ; while ( $ cpu = $ CPUs -> Next ( ) ) { $ cpuLoad += $ cpu -> LoadPercentage ; $ i ++ ; } $ cpuLoad = round ( $ cpuLoad / $ i , 2 ) ; return $ cpuLoad . '%' ; } } throw new Exception ( 'Unable to get server load' ) ; }
Get server load ... if linux, returns all three averages, if windows, returns
average load for all CPU cores

@return string
@throws Exception
Get server load ... if linux returns all three averages if windows returns average load for all CPU cores