irwan

PHP : Get info about your memory usage

Mar 16th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2. echo "Initial: ".memory_get_usage()." bytes \n";
  3. /* prints
  4. Initial: 361400 bytes
  5. */
  6.  
  7. // let's use up some memory
  8. for ($i = 0; $i < 100000; $i++) {
  9.     $array []= md5($i);
  10. }
  11.  
  12. // let's remove half of the array
  13. for ($i = 0; $i < 100000; $i++) {
  14.     unset($array[$i]);
  15. }
  16.  
  17. echo "Final: ".memory_get_usage()." bytes \n";
  18. /* prints
  19. Final: 885912 bytes
  20. */
  21.  
  22. echo "Peak: ".memory_get_peak_usage()." bytes \n";
  23. /* prints
  24. Peak: 13687072 bytes
  25. */
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment