WordPress Display memory consumption & #038; load

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.