Created
October 24, 2020 01:50
-
-
Save inonote/7e4f1c10779748419ac19815de6a3268 to your computer and use it in GitHub Desktop.
/proc/meminfo から読み取った内容を連想配列にするPHPスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function meminfo(){ | |
| $ret = array(); | |
| $txt = shell_exec('cat /proc/meminfo'); | |
| $lines = explode("\n", $txt); | |
| foreach($lines as $line){ | |
| if ($line === '') continue; | |
| $data = explode(':', $line, 2); | |
| $value = trim($data[1]); | |
| // 単位変換 | |
| if (substr($value, -3) === ' kB') | |
| $value = (float)substr($value, 0, -3) * 1024; | |
| else | |
| $value = (float)$value; | |
| $ret[$data[0]] = $value; | |
| } | |
| return $ret; | |
| } | |
| var_dump(meminfo()); | |
| /* | |
| array(n) { | |
| ["MemTotal"]=> | |
| float(215073608448) | |
| ["MemFree"]=> | |
| float(27390679296) | |
| ... | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment