获取有关内存使用情况的信息。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取有关内存使用情况的信息。相关的知识,希望对你有一定的参考价值。

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 ";
  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 ";
  17. /* prints
  18. Final: 885912 bytes
  19. */
  20.  
  21. echo "Peak: ".memory_get_peak_usage()." bytes ";
  22. /* prints
  23. Peak: 13687072 bytes
  24. */

以上是关于获取有关内存使用情况的信息。的主要内容,如果未能解决你的问题,请参考以下文章