Created
August 30, 2017 07:17
-
-
Save hlorand/67acccd1d76caffea8a3ef5487a2549a to your computer and use it in GitHub Desktop.
Server memory usage checker
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
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta http-equiv="refresh" content="1"> | |
| </head> | |
| <body> | |
| Server memory usage: | |
| <?php | |
| $data = explode("\n", file_get_contents("/proc/meminfo")); | |
| $meminfo = array(); | |
| foreach ($data as $line) { | |
| list($key, $val) = explode(":", $line); | |
| $meminfo[$key] = explode(" ",trim($val))[0]; | |
| $meminfo[$key] = number_format((double)$meminfo[$key], 0, '.', ' ') . " kb"; | |
| } | |
| echo "<pre>"; | |
| print_r($meminfo); | |
| echo "</pre>"; | |
| ?> | |
| <?php | |
| function convert($size) | |
| { | |
| $unit=array('b','kb','mb','gb','tb','pb'); | |
| return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; | |
| } | |
| echo "Memory used by this page: " . convert(memory_get_usage(true)); | |
| ?> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment