Skip to content

Instantly share code, notes, and snippets.

@craiga
Last active August 29, 2015 14:15
Show Gist options
  • Save craiga/9e35e52168aefe58b9eb to your computer and use it in GitHub Desktop.
Save craiga/9e35e52168aefe58b9eb to your computer and use it in GitHub Desktop.
/**
* 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