Skip to content

Instantly share code, notes, and snippets.

@hlorand
Created August 30, 2017 07:17
Show Gist options
  • Select an option

  • Save hlorand/67acccd1d76caffea8a3ef5487a2549a to your computer and use it in GitHub Desktop.

Select an option

Save hlorand/67acccd1d76caffea8a3ef5487a2549a to your computer and use it in GitHub Desktop.
Server memory usage checker
<!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