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.
Php obtains real-time cpu memory usage in windows (recommended) and phpcpu
The CPU and memory usage of the backend Real-time Monitoring Server is very common. Although I have never done so, I did not expect it to take more than two hours to
Metrics to measure CPU performance:1, the user uses the CPU situation;CPU runs regular user processesCPU Running niced ProcessCPU running real-time process2, the system uses CPU condition;For I/O Management: interrupts and drivesFor memory
How does php obtain the current cpu usage of centos.
I use
$ Str = shell_exec ('more/proc/stat ');
Or
Popen ('top-B-n 2 | grep-E "(Cpu)" ', "r ");
It seems that the result is not accurate. The result is 0.4% every time, but the top check on
Metrics to measure CPU performance:1, the user uses the CPU situation;CPU runs regular user processesCPU Running niced ProcessCPU running real-time process2, the system uses CPU condition;For I/O Management: interrupts and drivesFor memory
Sometimes, a Linux server running Nginx, php-cgi (PHP-FPM) Web services suddenly has a system load that is viewed with the top command, with a lot of php-cgi process CPU usage approaching 100%. Later, I tracked and found that this kind of situation
How does php obtain the current cpu usage of centos. I use $ str & nbsp; shell_exec (more & nbsp; procstat); or popen (top & nbsp;-B & nbsp;-n & nbsp; 2 & nbsp; | & nbsp; grep & nbsp;-E & nbsp; (Cpu), r); the result seems to be inaccurate. how does
It is also important to limit the use of the CPU to prevent server crashes. This is especially useful for any custom scripts you might run in a crontab. First, we're going to spin up an Ubuntu 12.10 x64 droplet:
Install CPULimit
Apt-get-y Install
Php code for obtaining unique computer ID information (cpu, network card, MAC address)
The php code obtains the unique identifier information of a computer, including cpu information, network card information, and MAC address information.
Title.
I use
$str = shell_exec (' More/proc/stat ');
Or
Popen (' Top-b-N 2 | grep-e "(CPU)" ', "R");
Take the image is not accurate, each time is 0.4%, but on the server with top view change is 0.7,1.0,14 ...
How to get it fast?
Reply to
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.