Plugin Directory

Changeset 3250660


Ignore:
Timestamp:
03/04/2025 07:53:38 PM (12 months ago)
Author:
bitslip6
Message:

ensure all vars are init in get sys info, even if stats are not available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bitfire/tags/4.5.0/src/api.php

    r3250658 r3250660  
    16991699    }
    17001700   
    1701     $cpu = 1;
     1701    $cpu = $load = $mem_total = $mem_free = $cached = $swap = 1;
    17021702    if (file_exists("/proc/cpuinfo") && is_readable("/proc/cpuinfo")) {
    17031703        $raw = file_get_contents('/proc/cpuinfo');
     
    17071707    }
    17081708
    1709     $raw = file_get_contents('/proc/loadavg');
    1710     $load = explode(' ', $raw);
    1711 
    1712     $raw = file_get_contents('/proc/meminfo');
    1713 
    1714     $mem_total = $mem_free = $cached = $swap = 0;
    1715     if (preg_match('/MemTotal:\s+(\d+)/ims', $raw, $tmp)) {
    1716         $mem_total = $tmp[1];
    1717     }
    1718     if (preg_match('/MemFree:\s+(\d+)/ims', $raw, $tmp)) {
    1719         $mem_free = $tmp[1];
    1720     }
    1721     if (preg_match('/Cached:\s+(\d+)/ims', $raw, $tmp)) {
    1722         $cached = $tmp[1];
    1723     }
    1724     if (preg_match('/SwapTotal:\s+(\d+)/ims', $raw, $tmp)) {
    1725         $swap1 = $tmp[1];
    1726         if (preg_match('/SwapFree:\s+(\d+)/ims', $raw, $tmp)) {
    1727             $swap2 = $tmp[1];
    1728             $swap = intval($swap1) - intval($swap2);
     1709    if (file_exists("/proc/loadavg") && is_readable("/proc/loadavg")) {
     1710        $raw = file_get_contents('/proc/loadavg');
     1711        $load = explode(' ', $raw);
     1712    }
     1713
     1714    if (file_exists("/proc/meminfo") && is_readable("/proc/meminfo")) {
     1715        $raw = file_get_contents('/proc/meminfo');
     1716
     1717        $mem_total = $mem_free = $cached = $swap = 0;
     1718        if (preg_match('/MemTotal:\s+(\d+)/ims', $raw, $tmp)) {
     1719            $mem_total = $tmp[1];
     1720        }
     1721        if (preg_match('/MemFree:\s+(\d+)/ims', $raw, $tmp)) {
     1722            $mem_free = $tmp[1];
     1723        }
     1724        if (preg_match('/Cached:\s+(\d+)/ims', $raw, $tmp)) {
     1725            $cached = $tmp[1];
     1726        }
     1727        if (preg_match('/SwapTotal:\s+(\d+)/ims', $raw, $tmp)) {
     1728            $swap1 = $tmp[1];
     1729            if (preg_match('/SwapFree:\s+(\d+)/ims', $raw, $tmp)) {
     1730                $swap2 = $tmp[1];
     1731                $swap = intval($swap1) - intval($swap2);
     1732            }
    17291733        }
    17301734    }
Note: See TracChangeset for help on using the changeset viewer.