Php code for obtaining CPU usage

Source: Internet
Author: User
Tags php example
Php code for obtaining CPU usage
Share a few php code to get the cpu usage in the current system. if you need it, give it a reference.

In php, you can use getrusage () to obtain CPU usage. this method is only applicable to linux systems. Example:

     0 [ru_inblock] => 0 [ru_msgsnd] => 2 [ru_msgrcv] => 3 [ru_maxrss] => 12692 [ru_ixrss] => 764 [ru_idrss] => 3864 [ru_minflt] => 94 [ru_majflt] => 0 [ru_nsignals] => 1 [ru_nvcsw] => 67 [ru_nivcsw] => 4 [ru_nswap] => 0 [signature] => 0 [signature [ru_utime. TV _sec] => 0 [ru_stime. TV _usec] => 6269 [ru_stime. TV _sec] => 0) */

Explanation: ru_oublock: block output operation ru_inblock: block input operation ru_msgsnd: sent messageru_msgrcv: received messageru_maxrss: maximum resident set size small ru_ixrss: all shared memory size ru_idrss: all non-shared memory size ru_minflt: page recycling ru_majflt: Page failure ru_nsignals: Received signal ru_nvcsw: active context switching ru_nivcsw: passive context switching ru_nswap: Swap Zone duration: User state Time (microseconds) ru_utime. TV _sec: User State time (seconds) ru_stime. TV _usec: System Kernel time (microseconds) ru_stime. TV _sec: System Kernel time? (Seconds) sometimes you need to check how much CPU the script consumes. you need to check the values of "user-mode time" and "system kernel time. The second and microsecond sections are provided separately. you can divide the microsecond value by 1 million and add it to the second value to obtain the number of seconds with the decimal part. Example:

     

Sleep does not occupy the system time. for example:

      

The running of the above code consumes about 14 seconds of CPU time, and almost all of them are user time, because there is no system call. The system time is the time when the CPU spends executing kernel commands on system calls. Example:

       

The above example shows a higher level of cpu consumption. Articles you may be interested in: php file_get_contents causes soaring cpu usage solution php obtains CPU usage code php uses proc/loadavg to monitor average CPU load php records server load, memory, and cpu status code php example of page cache (reducing the cpu and mysql burden) php code for obtaining cpu and memory usage example php code for obtaining CPU, memory, and hard disk usage of linux servers php code for obtaining unique computer identification information (cpu, Nic, MAC address) code PHP-CGI process CPU 100% and file_get_contents function relationship php program random record mysql rand () cause CPU 100% solution

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.