diff options
author | Patrik Kernstock <info@pkern.at> | 2017-05-26 13:30:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-26 13:30:21 +0300 |
commit | 0952447cbe8892cc7cc79d1bd8d9bdbae609b9b1 (patch) | |
tree | f8c0892857b1b812b7b53cadd4dd55f751a5aa4d /lib | |
parent | 1f45054955d9c56db1f68a46b9ba5a64367fbba6 (diff) |
Use is_readable() to check if meminfo can be read
IMHO it's a bit more elegant way to check if meminfo can be read using is_readable(), instead of suppressing all warnings and errors for file_get_contents(). (@ is changing the whole error_reporting() temporarly, so it should be avoided)
Signed-off-by: Patrik Kernstock <info@pkern.at>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/SystemStatistics.php | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index dd483a5..28966de 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -68,7 +68,12 @@ class SystemStatistics { * @return array with the two values 'mem_free' and 'mem_total' */ protected function getMemoryUsage() { - $memoryUsage = @file_get_contents('/proc/meminfo'); + $memoryUsage = false; + if (is_readable('/proc/meminfo')) { + // read meminfo from OS + $memoryUsage = file_get_contents('/proc/meminfo'); + } + // check if determining memoryUsage failed if ($memoryUsage === false) { return ['mem_free' => 'N/A', 'mem_total' => 'N/A']; } |