PHP code example of hejunjie / hardware-monitor
1. Go to this page and download the library: Download hejunjie/hardware-monitor library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hejunjie / hardware-monitor example snippets
use Hejunjie\HardwareMonitor\CPUInfo;
$cpuInfo = CPUInfo::getCpuInfo();
echo 'CPU 模型: ' . $cpuInfo['model'];
echo '物理核心数: ' . $cpuInfo['cores'];
echo '逻辑核心数: ' . $cpuInfo['logical_cores'];
echo '每个插槽的核心数: ' . $cpuInfo['cores_per_socket'];
use Hejunjie\HardwareMonitor\CPUInfo;
$cpuUsage = CPUInfo::getCpuUsage();
echo '用户空间占用 CPU 时间的百分比: ' . $cpuUsage['user'];
echo '内核空间占用 CPU 时间的百分比: ' . $cpuUsage['sys'];
echo '空闲时间的百分比: ' . $cpuUsage['idle'];
echo '等待 I/O 操作的时间百分比: ' . $cpuUsage['wait'];
use Hejunjie\HardwareMonitor\MemoryInfo;
$memoryInfo = MemoryInfo::getMemoryUsage();
echo '总内存: ' . $memoryInfo['total'] . ' MB';
echo '已用内存: ' . $memoryInfo['used'] . ' MB';
echo '空闲内存: ' . $memoryInfo['free'] . ' MB';
echo '缓存内存: ' . $memoryInfo['cached'] . ' MB';
echo '缓冲区内存: ' . $memoryInfo['buffers'] . ' MB';
use Hejunjie\HardwareMonitor\DiskInfo;
$diskInfo = DiskInfo::getDiskInfo();
foreach ($diskInfo as $disk) {
echo '硬盘设备名称: ' . $disk['device'];
echo '硬盘型号: ' . $disk['model'];
echo '大小: ' . $disk['size'] . ' MB';
echo '已用: ' . $disk['used'] . ' MB';
echo '空闲: ' . $disk['free'] . ' MB';
echo '占用百分比: ' . $disk['capacity'];
echo '文件系统类型: ' . $disk['filesystem'];
echo '挂载点: ' . $disk['mountpoint'];
}
use Hejunjie\HardwareMonitor\NetworkTraffic;
$networkTraffic = NetworkTraffic::getNetworkTraffic();
foreach ($networkTraffic as $network) {
echo '网络接口: ' . $network['name'];
echo '流入流量: ' . $network['in'] . ' MB';
echo '流出流量: ' . $network['out'] . ' MB';
}