PHP了解你的記憶體使用情況

2021-06-07 21:42:30 字數 566 閱讀 3784

為了優化你的指令碼,你需要了解伺服器上的ram使用情況。這個**片段將幫助你了解記憶體使用,並且列印初始、最終以及峰值使用情況。

echo "initial: ".memory_get_usage()." bytes \n";

/* prints

initial: 361400 bytes

*/// let's use up some memory

for ($i = 0; $i < 100000; $i++)

// let's remove half of the array

for ($i = 0; $i < 100000; $i++)

echo "final: ".memory_get_usage()." bytes \n";

/* prints

final: 885912 bytes

*/echo "peak: ".memory_get_peak_usage()." bytes \n";

/* prints

peak: 13687072 bytes

*/

PHP獲取記憶體使用情況

php內建函式memory get usage 能返回當前分配給php指令碼的記憶體量,單位是位元組 byte 在web實際開發中,這些函式非常有用,我們可以使用它來除錯php 效能。memory get usage 函式返回記憶體使用量,memory get peak usage 函式返回記憶體使...

現在php記憶體使用 PHP獲取記憶體使用情況

memory get usage 函式返回記憶體使用量,memory get peak usage 函式返回記憶體使用峰值,getrusage 返回cup使用情況。但有一點請注意,在這些函式需要在linux上執行。下面我們來看乙個例項 echo 開始記憶體 memory get usage tmp ...

Linux 記憶體使用情況

linux系統如何檢視使用記憶體情況 root r2 free total used free shared buffers cached mem 215608 142680 72928 0 19736 86956 buffers cache 35988 179620 swap 1052248 0 ...