PHPackages                             hejunjie/hardware-monitor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hejunjie/hardware-monitor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hejunjie/hardware-monitor
=========================

一个轻量级的 PHP 包，用于获取和监控系统硬件参数。支持获取 CPU 型号和性能信息、内存使用情况、硬盘信息及网络流量数据。通过执行系统命令并使用正则表达式解析输出结果，实时获取硬件性能数据。适用于 PHP8，支持加入原有项目定时任务多次调用以实现硬件监控，帮助开发者监控系统资源使用情况，优化系统性能。

v1.0.1(1y ago)3317↓41.7%MITPHPPHP ^8.0

Since Dec 4Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/zxc7563598/php-hardware-monitor)[ Packagist](https://packagist.org/packages/hejunjie/hardware-monitor)[ RSS](/packages/hejunjie-hardware-monitor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

硬件信息 Composer 包
===============

[](#硬件信息-composer-包)

这个 Composer 包提供了一种简单而高效的方式来获取硬件信息，如 CPU 详情、内存使用情况、磁盘空间和网络流量，支持 Linux 和 macOS 系统。它封装了系统命令来获取这些数据，并以结构化的格式返回。

> Windows 系统测试中，近期更新

功能
--

[](#功能)

- 获取 CPU 模型、核心数和逻辑核心数。
- 获取系统内存使用情况（总内存、已用内存、空闲内存、缓存内存、缓冲区内存）。
- 获取详细的磁盘信息，包括容量、已用空间和挂载点。
- 获取实时的网络流量统计。
- 支持 Linux 和 macOS 操作系统。

系统要求
----

[](#系统要求)

- PHP 8.0 或更高版本
- 支持 Linux 或 macOS 操作系统
- 需要使用 Composer 进行依赖管理

安装
--

[](#安装)

你可以通过 Composer 安装这个包。在项目目录下运行以下命令：

```
composer require hejunjie/hardware-monitor
```

使用方法
----

[](#使用方法)

### 获取 CPU 信息

[](#获取-cpu-信息)

要获取 CPU 信息（如模型、核心数、逻辑核心数）：

```
use Hejunjie\HardwareMonitor\CPUInfo;

$cpuInfo = CPUInfo::getCpuInfo();
echo 'CPU 模型: ' . $cpuInfo['model'];
echo '物理核心数: ' . $cpuInfo['cores'];
echo '逻辑核心数: ' . $cpuInfo['logical_cores'];
echo '每个插槽的核心数: ' . $cpuInfo['cores_per_socket'];
```

### 获取 CPU 使用情况

[](#获取-cpu-使用情况)

获取 CPU 使用情况：

```
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';
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance55

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Total

2

Last Release

508d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b65d4b40ae456172fb38f63f84bf737ac88031484b1f228b1cc8d71baa80adf?d=identicon)[苏青安](/maintainers/%E8%8B%8F%E9%9D%92%E5%AE%89)

---

Top Contributors

[![zxc7563598](https://avatars.githubusercontent.com/u/46590942?v=4)](https://github.com/zxc7563598 "zxc7563598 (17 commits)")

### Embed Badge

![Health badge](/badges/hejunjie-hardware-monitor/health.svg)

```
[![Health](https://phpackages.com/badges/hejunjie-hardware-monitor/health.svg)](https://phpackages.com/packages/hejunjie-hardware-monitor)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
