PHP脚本来获取每个进程的CPU利用率? [英] php script to get cpu utilization for each process?
问题描述
如何获取当前使用PHP在本地系统或服务器上当前正在运行的每个进程的CPU使用率。
How do I get the CPU usage for each process that is currently running on the local system or server using PHP.
如何使用命令提示符命令任务列表
在PHP中,并获取进程名称和内存信息。
How can I use the Command Prompt command tasklist
from within PHP and fetch process names and memory information.
这里是示例:
Name of Processor Memory usage
Edit plus 6.1 MB
Google Chrome 20 MB
Command Prompt 5 MB
Tomcat 2.1 MB
推荐答案
答案的规范,我不想删除或屠杀我的其他答案,这可能是其他人可以接受的解决方案。
Seeing as you've changed the specification for the answer and I don't wish to remove or butcher my other answer which may be an acceptable solution for others.
如果您必须 >使用命令提示符命令 tasklist
检索过程数据,然后可以使用 exec()
从PHP。
If you MUST use the Command Prompt command tasklist
to retrieve the process data then you can then call this Application using exec()
from PHP.
<?php
exec('tasklist.exe', $outputLines);
foreach($line in $outputLines)
{
//Extract information from String...
}
?>
然后您将需要使用String操作提取所需的信息。正则表达式可能是一个不错的选择。
You will then need to use String manipulation to extract the information you want. Regex might be a good choice.
这篇关于PHP脚本来获取每个进程的CPU利用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!