Merge pull request #12015 from annando/proc-access

Check the readability before acessing /proc/loadavg
This commit is contained in:
Tobias Diekershoff 2022-10-18 11:14:19 +02:00 committed by GitHub
commit 27376a3dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -442,10 +442,13 @@ class System
*/ */
public static function getLoadAvg(): array public static function getLoadAvg(): array
{ {
$content = @file_get_contents('/proc/loadavg'); if (is_readable('/proc/loadavg')) {
if (empty($content)) { $content = @file_get_contents('/proc/loadavg');
$content = shell_exec('cat /proc/loadavg'); if (empty($content)) {
$content = shell_exec('cat /proc/loadavg');
}
} }
if (empty($content) || !preg_match("#([.\d]+)\s([.\d]+)\s([.\d]+)\s(\d+)/(\d+)#", $content, $matches)) { if (empty($content) || !preg_match("#([.\d]+)\s([.\d]+)\s([.\d]+)\s(\d+)/(\d+)#", $content, $matches)) {
$load_arr = sys_getloadavg(); $load_arr = sys_getloadavg();
if (empty($load_arr)) { if (empty($load_arr)) {