WordPress showing memory footprint & Load Introduction
By adding a custom function to the functions.php in the WordPress topic file, the current system memory usage, overall BOM publishing memory and system load can be displayed when the page is open.
The function of this paper is to get the memory of the black probe, and the other needs to be picked up by itself.
Presentation results:
Completion method
Custom functions into the functions.php.
Total Physical Memory:
function Memtotal () { $str = @file ("/proc/meminfo"); $str = Implode ("", $str); Preg_match_all ("/memtotal\s{0,}\:+\s{0,} ([\d\.] +).+? Memfree\s{0,}\:+\s{0,} ([\d\.] +).+? Cached\s{0,}\:+\s{0,} ([\d\.] +).+? Swaptotal\s{0,}\:+\s{0,} ([\d\.] +).+? Swapfree\s{0,}\:+\s{0,} ([\d\.] +)/S ", $str, $buf); Preg_match_all ("/buffers\s{0,}\:+\s{0,} ([\d\.] +)/S ", $str, $buffers); $memTotal = Round ($buf [1][0]/1024, 2); return $memTotal;}
Memory usage:
function memused () { $str = @file ("/proc/meminfo"); $str = Implode ("", $str); Preg_match_all ("/memtotal\s{0,}\:+\s{0,} ([\d\.] +).+? Memfree\s{0,}\:+\s{0,} ([\d\.] +).+? Cached\s{0,}\:+\s{0,} ([\d\.] +).+? Swaptotal\s{0,}\:+\s{0,} ([\d\.] +).+? Swapfree\s{0,}\:+\s{0,} ([\d\.] +)/S ", $str, $buf); Preg_match_all ("/buffers\s{0,}\:+\s{0,} ([\d\.] +)/S ", $str, $buffers); $memTotal = Round ($buf [1][0]/1024, 2); $memFree = Round ($buf [2][0]/1024, 2); $memUsed = $memTotal-$memFree; return $memUsed;}
Real Memory Usage:
function memrealused () { $str = @file ("/proc/meminfo"); $str = Implode ("", $str); Preg_match_all ("/memtotal\s{0,}\:+\s{0,} ([\d\.] +).+? Memfree\s{0,}\:+\s{0,} ([\d\.] +).+? Cached\s{0,}\:+\s{0,} ([\d\.] +).+? Swaptotal\s{0,}\:+\s{0,} ([\d\.] +).+? Swapfree\s{0,}\:+\s{0,} ([\d\.] +)/S ", $str, $buf); Preg_match_all ("/buffers\s{0,}\:+\s{0,} ([\d\.] +)/S ", $str, $buffers); $memTotal = Round ($buf [1][0]/1024, 2); $memFree = Round ($buf [2][0]/1024, 2); $memCached = Round ($buf [3][0]/1024, 2); $memBuffers = Round ($buffers [1][0]/1024, 2) ; $memRealUsed = $memTotal-$memFree-$memCached-$memBuffers; return $memRealUsed;}
System load:
function Loadavg () { $str = @file ("/proc/loadavg"); $str = Explode ("", Implode ("", $str)); $str = Array_chunk ($str, 4); $LOADAVG = Implode ("", $str [0]); return $LOADAVG;}
Example of a function invocation method:
Echo Memtotal (); # Overall BOM Publishing physical memory
Some of the contents refer to:
Http://www.weishimi.com/archives/114.html
Hope that the above article is useful to you, if you feel good give me the top! More and WordPress display memory consumption & load related issues or to foreign host evaluation have doubts also welcome everyone consultation.
WordPress Display memory consumption & #038; load