Last active
August 29, 2015 14:15
-
-
Save craiga/9e35e52168aefe58b9eb to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Get memory usage information. | |
* | |
* Requires {@link https://gist.github.com/3759346 strtobytes}. | |
* | |
* @author Craig Anderson <craiga@craiga.id.au> | |
* @link https://gist.github.com/craiga/9e35e52168aefe58b9eb | |
*/ | |
function get_mem_info() | |
{ | |
$memInfo = array(); | |
if (file_exists("/proc/meminfo")) { | |
$rawMemInfo = file_get_contents("/proc/meminfo"); | |
$memInfoLines = explode("\n", $rawMemInfo); | |
foreach ($memInfoLines as $memInfoLine) { | |
$memInfoData = preg_split("/:\s+/", $memInfoLine, 2); | |
if (count($memInfoData) == 2) { | |
$memInfo[$memInfoData[0]] = strtobytes($memInfoData[1]); | |
} | |
} | |
} | |
return $memInfo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment