2013-07-15 25 views
0

有沒有簡單的方法來檢查某個數組佔用多少內存?檢查PHP數組佔用多少內存

就像我已經得到了一些10K行陣列,並且需要知道多少MB/KB需要服務器記住它裏面的一些$arr

回答

1
// how much memory are you using before building your array 
$baseMemory = memory_get_usage(false); 
// create your array 
$a = array('A',1,'B',2); 
// how much memory are you using now the array is built 
$finalMemory = memory_get_usage(false); 
// the difference is a pretty close approximation 
$arrayMemory = $finalMemory - $baseMemory;