首页 > 开发 > PHP > 正文

php 查看使用了多少内存

2024-05-04 21:51:00
字体:
来源:转载
供稿:网友

方法memory_get_usage 是指当前脚本正在使用的内存

unset只是把内存标记为空闲但并没有释放,要GC程序结束后才会释放

  1. $bytes = memory_get_peak_usage(); 
  2.   
  3. function formatBytes($bytes$precision = 2) { 
  4.  
  5.     $units = array("b""kb""mb""gb""tb"); 
  6.   
  7.     $bytes = max($bytes, 0); 
  8.  
  9.     $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); 
  10.  
  11.     $pow = min($powcount($units) - 1);  
  12.  
  13.     $bytes /= (1 << (10 * $pow));  
  14.  
  15.     return round($bytes$precision) . " " . $units[$pow]; 
  16.  
  17.  
  18.  
  19. echo formatBytes($bytes); 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表