Skip to content

Instantly share code, notes, and snippets.

@chinthakagodawita
Created September 12, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chinthakagodawita/bf3c690cdf5242cf5209fe59cd00e52c to your computer and use it in GitHub Desktop.
Save chinthakagodawita/bf3c690cdf5242cf5209fe59cd00e52c to your computer and use it in GitHub Desktop.
PHP memory usage as reported by the kernel
<?php
function memory_get_process_usage()
{
$status = file_get_contents('/proc/' . getmypid() . '/status');
$matchArr = [];
preg_match_all('~^(VmRSS|VmSwap):\s*([0-9]+).*$~im', $status, $matchArr);
if (!isset($matchArr[2][0], $matchArr[2][1])) {
return false;
}
return ((int)$matchArr[2][0] + (int)$matchArr[2][1]) / 1024;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment