Get info about your memory usage.


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. echo "Initial: ".memory_get_usage()." bytes \n";
  2. /* prints
  3. Initial: 361400 bytes
  4. */
  5.  
  6. // let's use up some memory
  7. for ($i = 0; $i < 100000; $i++) {
  8. $array []= md5($i);
  9. }
  10.  
  11. // let's remove half of the array
  12. for ($i = 0; $i < 100000; $i++) {
  13. unset($array[$i]);
  14. }
  15.  
  16. echo "Final: ".memory_get_usage()." bytes \n";
  17. /* prints
  18. Final: 885912 bytes
  19. */
  20.  
  21. echo "Peak: ".memory_get_peak_usage()." bytes \n";
  22. /* prints
  23. Peak: 13687072 bytes
  24. */

URL: http://net.tutsplus.com/tutorials/php/9-useful-php-functions-and-features-you-need-to-know/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.