獲取 PHP 中物件在記憶體中的大小?


可以在為已建立類分配記憶體之前和之後使用 memory_get_usage() 函式。

class MyBigClass {
   var $allocatedSize;
   var $allMyOtherStuff;
}
function AllocateMyBigClass() {
   $before = memory_get_usage();
   $ret = new MyBigClass;
   $after = memory_get_usage();
   $ret->allocatedSize = ($after - $before);
   return $ret;
}

輸出將是物件在環境設定方面的記憶體。

更新於: 2020 年 4 月 7 日

2K+ 檢視次數

開啟你的 職業之路

完成課程即可獲得認證

開始
廣告
© . All rights reserved.