Skip to content

Instantly share code, notes, and snippets.

@abbotto
Created October 26, 2012 16:02
Show Gist options
  • Save abbotto/3959626 to your computer and use it in GitHub Desktop.
Save abbotto/3959626 to your computer and use it in GitHub Desktop.
Get Info About Memory Usage.
<?
// In order to optimize your scripts, you may definitely want to know how many amount of RAM they use on your server. This snippet will check memory and then print initial, final and peak usages.
echo "Initial: ".memory_get_usage()." bytes \n";
/* prints
Initial: 361400 bytes
*/
// let's use up some memory
for ($i = 0; $i < 100000; $i++) {
$array []= md5($i);
}
// let's remove half of the array
for ($i = 0; $i < 100000; $i++) {
unset($array[$i]);
}
echo "Final: ".memory_get_usage()." bytes \n";
/* prints
Final: 885912 bytes
*/
echo "Peak: ".memory_get_peak_usage()." bytes \n";
/* prints
Peak: 13687072 bytes
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment