{"id":17343121,"url":"https://github.com/danielme85/simple-server-info","last_synced_at":"2026-02-23T20:26:59.960Z","repository":{"id":56961948,"uuid":"147898584","full_name":"danielme85/simple-server-info","owner":"danielme85","description":"Get CPU information and load. Memory and storage/volume usage and information. Made with efficiency and simplicity in mind. ","archived":false,"fork":false,"pushed_at":"2023-02-17T18:05:44.000Z","size":39,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T08:12:11.754Z","etag":null,"topics":["cpu","information-retrieval","memory","php7","procfs","server","storage","sysinfo","system","uptime","volumes"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielme85.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-08T03:45:50.000Z","updated_at":"2023-05-12T16:52:16.000Z","dependencies_parsed_at":"2022-08-21T05:40:19.608Z","dependency_job_id":null,"html_url":"https://github.com/danielme85/simple-server-info","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Fsimple-server-info","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Fsimple-server-info/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Fsimple-server-info/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Fsimple-server-info/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielme85","download_url":"https://codeload.github.com/danielme85/simple-server-info/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952019,"owners_count":21188421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu","information-retrieval","memory","php7","procfs","server","storage","sysinfo","system","uptime","volumes"],"created_at":"2024-10-15T16:08:28.545Z","updated_at":"2026-02-23T20:26:59.947Z","avatar_url":"https://github.com/danielme85.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Simple Server Info\n\n[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/danielme85/simple-server-info)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/danielme85/simple-server-info.svg?style=flat-square)](https://packagist.org/packages/danielme85/simple-server-info)\n[![GitHub release](https://img.shields.io/github/release/danielme85/simple-server-info.svg?style=flat-square)](https://packagist.org/packages/danielme85/simple-server-info)\n[![GitHub tag](https://img.shields.io/github/tag/danielme85/simple-server-info.svg?style=flat-square)](https://github.com/danielme85/simple-server-info)\n\nA PHP 8.1+ library that reads server and system information directly from the Linux\n[`/proc`](https://en.wikipedia.org/wiki/Procfs) and `/sys` virtual filesystems.\n\nNo `exec`, `shell_exec`, or other shell commands are used — all data is read from virtual\nfilesystem files, making this safe, portable, and easy to audit.\n\n---\n\n## Requirements\n\n* Linux/Unix OS with [Procfs](https://en.wikipedia.org/wiki/Procfs) support (`/proc`).\n* PHP 8.1 or later.\n\n---\n\n## Installation\n\n```bash\ncomposer require danielme85/simple-server-info\n```\n\n---\n\n## Quick start\n\n```php\nuse danielme85\\Server\\Info;\n\n// Instantiate directly\n$info = new Info();\n\n// Or use the static factory for method chaining\n$cpuLoad = Info::get()-\u003ecpuLoad(sampleSec: 1, rounding: 2);\n```\n\n---\n\n## Architecture\n\nThe library is organised around small, focused **Collector** classes, each responsible for a\nsingle concern. The `Info` class is a **facade** that delegates to the collectors while\npreserving a clean, unified API.\n\n```\nsrc/\n├── Contracts/\n│   └── CollectorInterface.php   # Interface implemented by every collector\n├── Collectors/\n│   ├── AbstractCollector.php    # Shared parsing helpers\n│   ├── CpuCollector.php         # CPU info \u0026 load\n│   ├── DiskCollector.php        # Disk partitions \u0026 volumes\n│   ├── GpuCollector.php         # GPU info \u0026 resource usage\n│   ├── MemoryCollector.php      # RAM \u0026 swap\n│   ├── NetworkCollector.php     # Network interfaces \u0026 TCP connections\n│   ├── ProcessCollector.php     # Process listing \u0026 CPU usage\n│   └── SystemCollector.php      # Uptime \u0026 kernel version\n├── Formatter.php                # Byte-formatting helper\n├── Info.php                     # Public facade\n├── ProcReader.php               # Low-level /proc file reader\n└── SysReader.php                # Low-level /sys file reader\n```\n\nCollectors can be used independently:\n\n```php\nuse danielme85\\Server\\ProcReader;\nuse danielme85\\Server\\SysReader;\nuse danielme85\\Server\\Collectors\\CpuCollector;\nuse danielme85\\Server\\Collectors\\GpuCollector;\n\n$cpu = new CpuCollector(new ProcReader());\n$load = $cpu-\u003eload(sampleSec: 1);\n\n$gpu = new GpuCollector(new ProcReader(), new SysReader());\n$gpus = $gpu-\u003egpus();\n```\n\nOr accessed through the facade:\n\n```php\n$load = Info::get()-\u003ecpu()-\u003eload();\n```\n\n---\n\n## API Reference\n\n### CPU\n\n```php\n// All cores, all fields\n$cpuInfo = Info::get()-\u003ecpuInfo();\n\n// Single core, specific fields\n$core0 = Info::get()-\u003ecpuInfo(core: 0, returnonly: ['model_name', 'cpu_mhz', 'cache_size']);\n\n// Load percentage per core (samples over $sampleSec seconds)\n$cpuLoad = Info::get()-\u003ecpuLoad(sampleSec: 1, rounding: 2);\n// Returns: ['cpu' =\u003e ['label' =\u003e 'CPU', 'load' =\u003e 12.5], 'cpu0' =\u003e [...], ...]\n```\n\n### Memory\n\n```php\n// Usage summary with formatted sizes (e.g. \"512.00 MB\")\n$usage = Info::get()-\u003ememoryUsage();\n\n// Raw byte values\n$usageBytes = Info::get()-\u003ememoryUsage(formatSizes: false);\n\n// Percentage load\n$load = Info::get()-\u003ememoryLoad(rounding: 2);\n// Returns: ['load' =\u003e 42.5, 'swap_load' =\u003e 0.0]\n\n// Full /proc/meminfo dump (bytes)\n$all = Info::get()-\u003ememoryInfo();\n```\n\n### Disk \u0026 Volumes\n\n```php\n// Block device information from /proc/partitions\n$disks = Info::get()-\u003ediskInfo();\n\n// Mounted volume usage (filtered by filesystem type)\n$volumes = Info::get()-\u003evolumesInfo();\n\n// Customise which filesystem types to include\n$info = new Info(filesystemTypes: ['ext4', 'xfs']);\n$volumes = $info-\u003evolumesInfo();\n```\n\n### Processes\n\n```php\n// All processes (stat + status combined)\n$all = Info::get()-\u003eprocesses();\n\n// Single process\n$proc = Info::get()-\u003eprocess(pid: 1);\n\n// Filtered: specific fields, stat only, running only\n$running = Info::get()-\u003eprocesses(\n    returnonly: ['pid', 'comm', 'state', 'vsize'],\n    returntype: 'stat',\n    runningonly: true\n);\n\n// Active or running processes with CPU usage\n$active = Info::get()-\u003eprocessesActiveOrRunning(\n    returnonly: ['comm', 'state', 'pid', 'cpu_usage'],\n    returntype: 'stat'\n);\n```\n\n### Network\n\n```php\n// Network interface statistics\n$interfaces = Info::get()-\u003enetworks();\n\n// With per-second load calculation (adds a 1s sleep)\n$withLoad = Info::get()-\u003enetworks(returnOnly: ['face', 'bytes', 'bytes_out', 'load', 'load_out']);\n\n// TCP connections\n$connections = Info::get()-\u003etcpConnections(includeLocalhost: false);\n\n// Summarised by local IP:port\n$summary = Info::get()-\u003etcpConnectionsSummarized();\n```\n\n### System / Uptime\n\n```php\n$uptime = Info::get()-\u003euptime();\n// Returns:\n// [\n//   'current_unix' =\u003e 1700000000,\n//   'uptime_unix'  =\u003e 86400,\n//   'started_unix' =\u003e 1699913600,\n//   'started'      =\u003e '2023-11-13 12:00:00',\n//   'current'      =\u003e '2023-11-14 12:00:00',\n//   'uptime'       =\u003e '1:00:00:00',\n//   'uptime_text'  =\u003e '1 days, 0 hours, 0 minutes and 0 seconds',\n// ]\n\n$info = Info::get()-\u003eotherInfo();\n// Returns: ['version' =\u003e '...', 'version_signature' =\u003e '...']\n```\n\n### GPU\n\nReads GPU hardware info and resource usage from `/sys/class/drm/`. Supports AMD and\nNVIDIA (open kernel module) GPUs. Available fields depend on the installed driver —\nabsent metrics are simply omitted from the output.\n\n```php\n$gpus = Info::get()-\u003egpuInfo();\n// Returns an array keyed by card name, e.g.:\n// [\n//   'card0' =\u003e [\n//     'vendor'             =\u003e 'AMD',\n//     'vendor_id'          =\u003e '0x1002',\n//     'device_id'          =\u003e '0x687f',\n//     'vram_total'         =\u003e 8589934592,\n//     'vram_total_format'  =\u003e '8.00 GB',\n//     'vram_used'          =\u003e 1073741824,\n//     'vram_used_format'   =\u003e '1.00 GB',\n//     'vram_load'          =\u003e 12.5,\n//     'gpu_busy_percent'   =\u003e 34,\n//     'temperature_celsius'=\u003e 62.0,\n//   ],\n// ]\n\n// Or via the typed collector:\n$gpuCollector = Info::get()-\u003egpu();\n$gpus = $gpuCollector-\u003egpus();\n```\n\n### Formatting helper\n\n```php\nuse danielme85\\Server\\Formatter;\n\necho Formatter::bytes(1073741824); // \"1.00 GB\"\n\n// Also available as a static method on Info for backward compatibility:\necho Info::formatBytes(1073741824);\n```\n\n---\n\n## Extending\n\nExtend `AbstractCollector` to create a custom collector. `ProcReader` is always injected\nas `$this-\u003eproc`. Pass a `SysReader` as the second constructor argument if your collector\nneeds `/sys` access (`$this-\u003esys`).\n\n```php\nuse danielme85\\Server\\Contracts\\CollectorInterface;\nuse danielme85\\Server\\Collectors\\AbstractCollector;\n\nclass LoadAvgCollector extends AbstractCollector implements CollectorInterface\n{\n    public function all(): array\n    {\n        $lines = $this-\u003eproc-\u003elines('loadavg');\n        $parts = explode(' ', $lines[0] ?? '');\n\n        return [\n            '1min'  =\u003e (float) ($parts[0] ?? 0),\n            '5min'  =\u003e (float) ($parts[1] ?? 0),\n            '15min' =\u003e (float) ($parts[2] ?? 0),\n        ];\n    }\n}\n```\n\n---\n\n## Running Tests\n\n```bash\ncomposer install\n./vendor/bin/phpunit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielme85%2Fsimple-server-info","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielme85%2Fsimple-server-info","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielme85%2Fsimple-server-info/lists"}