Created
September 12, 2019 16:29
-
-
Save chinthakagodawita/bf3c690cdf5242cf5209fe59cd00e52c to your computer and use it in GitHub Desktop.
PHP memory usage as reported by the kernel
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 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