Posted By

o0110o on 10/26/12


Tagged

php info memory


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

o0110o
catrinho
Priestd09


Get info about your memory usage.


 / Published in: PHP
 

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

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.

  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. */

Report this snippet  

You need to login to post a comment.