boson-php/os-info
Lightweight PHP library to detect and describe the current operating system, exposing basic OS name/version/arch details for CLI and server environments. Useful for cross-platform scripts, installers, and runtime diagnostics.
boson-php/os-info package provides OS-level system information (e.g., CPU, memory, disk, network stats) via a read-only subtree split from boson-php/boson. This is useful for:
phpinfo() or dd() with granular OS metrics.top, df, etc.).spatie/laravel-activitylog (for audit logs), spatie/laravel-monitoring (for app-level metrics).sys_getloadavg(), shell_exec('free -m'), or php-unix extensions.Illuminate\Contracts\Foundation\Application).os-info may become obsolete or require updates.| Risk Area | Severity | Mitigation |
|---|---|---|
| Data Accuracy | High | Validate against sysctl, dmidecode, or lshw for critical deployments. |
| Performance Overhead | Medium | Benchmark OsInfo::get() in production-like environments. |
| Cross-Platform Support | Medium | Test on Linux/Windows/containers (e.g., Docker, Kubernetes). |
| Security | Low | Avoid exposing raw OS data in APIs; sanitize for logging. |
| Maintenance Burden | High | Fork or wrap in a Laravel package to add providers/listeners. |
composer require boson-php/os-info.use Boson\OsInfo\OsInfo;
$cpu = OsInfo::get()->cpu();
htop, free -m).// app/Providers/OsInfoServiceProvider.php
public function register() {
$this->app->singleton('os-info', function () {
return new OsInfo();
});
}
LaravelOsInfoServiceProvider, and publish it internally.cache:os-metrics or a system_metrics table.// app/Models/SystemMetric.php
class SystemMetric extends Model {
protected $casts = ['cpu_usage' => 'float'];
}
/proc access in containers).| Component | Compatibility Notes |
|---|---|
| PHP Version | Tested on PHP 7.4+ (assume no PHP 8.0+ features). |
| Laravel Version | No Laravel-specific code; assume works with 5.5+. |
| OS Support | Primarily Linux (check OsInfo::get()->os() for Windows_NT quirks). |
| Containerized | May need --privileged or volume mounts for /proc, /sys (Docker). |
| Windows | Limited testing; expect gaps in disk/CPU metrics. |
system:metrics Artisan command for manual checks./api/system/health) with auth.composer require for Laravel versions).boson-php/boson evolves, os-info may stagnate.composer.json (e.g., 1.0.0).boson-php/boson releases./proc (fix with chmod or container privileges).top/htop).try-catch and log errors to Sentry/Laravel logs.try {
$metrics = OsInfo::get();
} catch (\Exception $e) {
Log::error("OS Info failed: " . $e->getMessage());
}
$metrics->cpu()->usage)./proc access.OsInfo::get() is lightweight (~50–200ms on Linux), but avoid calling in loops.$metrics = Cache::remember('os.metrics', 10, function () {
return OsInfo::get();
});
How can I help you explore Laravel packages today?