PHP obtains the memory usage status memory_get_usage () function. The memory_get_usage function is provided for you in php to check the current memory usage on your server. with this function, we can check the server status in real time, next I will provide you with the memory_get_usage function in php, which can check the current memory usage on your server. with this function, we can check the server status in real time, next I will introduce the usage of memory_get_usage.
Format memory_get_usage () output
The code is as follows: |
|
Function convert ($ size ){ $ Unit = array ('B', 'KB', 'mb', 'GB', 'TB', 'petab '); Return @ round ($ size/pow (1024, ($ I = floor (log ($ size, 1024), 2 ). ''. $ unit [$ I]; } Echo convert (memory_get_usage (true )); ?> |
Output: 256 kb
The PHP memory_get_usage () function can also have a parameter $ real_usage with a Boolean value. The default value is FALSE, indicating that the obtained memory usage does not include the memory occupied by this function (PHP memory manager). if it is set to TRUE, the resulting memory does not include the memory occupied by this function (PHP memory manager.
Example
The code is as follows: |
|
If (! Function_exists ('memory _ get_usage ')) { Function memory_get_usage () { $ Pid = getmypid (); If (IS_WIN) { Exec ('tasklist/FI "PID eq '. $ pid.'"/FO list', $ output ); Return preg_replace ('/[^ 0-9]/', ', $ output [5]) * 1024; } Else { Exec ("ps-eo % mem, rss, pid | grep $ pid", $ output ); $ Output = explode ("", $ output [0]); Return $ output [1] * 1024; } } } |
...