Last active
January 18, 2016 15:03
-
-
Save ghacosta/69311976b12231fbe4cc to your computer and use it in GitHub Desktop.
Memory limit vs usage percent
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
<?php | |
$memory_limit = (int)trim(ini_get("memory_limit"),'M'); | |
function echo_memory_usage() { | |
$mem_usage = memory_get_usage(true); | |
if ($mem_usage < 1024) | |
echo $mem_usage." bytes"; | |
elseif ($mem_usage < 1048576) { | |
echo "memory usage: ".round($mem_usage/1024,2)." kilobytes"."<br>"; | |
echo "percent usage:".round((($mem_usage/1024) * 100 / ($GLOBALS['memory_limit'] * 1024)),2)."%"."<br>"; | |
} | |
else { | |
echo "memory usage: ".round($mem_usage/1048576,2)." megabytes"."<br>"; | |
echo "percent usage:".round((($mem_usage/1048576) * 100 / ($GLOBALS['memory_limit'])),2)."%"."<br>"; | |
} | |
echo "<br/>"; | |
} | |
echo "memory limit: ".$GLOBALS['memory_limit']. " megabytes"."<br>"; | |
for($i=1; $i<=10; $i++){ | |
//if wants to clear screen | |
//ob_end_clean(); | |
echo "$i ...<br>"; | |
echo_memory_usage(); | |
sleep(1); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment