Home > Backend Development > PHP Tutorial > PHP code to get memory usage information

PHP code to get memory usage information

WBOY
Release: 2016-07-25 08:45:42
Original
993 people have browsed it
Using this php code, you can know the RAM (memory) usage on your server.
  1. echo "Initial: ".memory_get_usage()." bytes n";
  2. /* prints
  3. Initial: 361400 bytes
  4. */
  5. // let's use up some memory
  6. for ($i = 0; $i < 100000; $i++) {
  7. $array []= md5($i);
  8. }
  9. // let's remove half of the array
  10. for ($i = 0; $i < 100000; $i++) {
  11. unset($array[$i]);
  12. }
  13. echo "Final: ".memory_get_usage()." bytes n";
  14. /* prints
  15. Final: 885912 bytes
  16. */
  17. echo "Peak: ". memory_get_peak_usage()." bytes n";
  18. /* prints
  19. Peak: 13687072 bytes
  20. */
Copy code

PHP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template