PHP code example of laragems / os-info

1. Go to this page and download the library: Download laragems/os-info 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/ */

    

laragems / os-info example snippets




aragems\OsInfo\OsInfo;
use Laragems\OsInfo\Platform;

$info = OsInfo::detect();

echo $info->name();              // Ubuntu, macOS, Microsoft Windows 11 Pro
echo $info->platform()->value;   // linux, macos, windows
echo $info->architecture();      // x86_64, arm64, x86
echo $info->memory()->totalBytes();
echo $info->cpu()->logicalCores();
echo $info->runtime()->currentUser();

if ($info->platform() === Platform::Linux) {
    echo 'Running on Linux';
}



use Laragems\OsInfo\OsInfo;

$os = OsInfo::detect();

printf(
    "%s %s on %s\n",
    $os->name(),
    $os->versionId() ?? 'unknown',
    $os->architecture(),
);

printf(
    "%d logical cores, %s RAM\n",
    $os->cpu()->logicalCores() ?? 0,
    number_format(($os->memory()->totalBytes() ?? 0) / 1024 / 1024 / 1024, 2) . ' GiB',
);

echo $os->runtime()->virtualizationType()->value;



use Laragems\OsInfo\OperatingSystemInfo;
use Laragems\OsInfo\OsInfo;

$payload = OsInfo::detect()->toArray();

echo $payload[OperatingSystemInfo::NAME];       // Ubuntu
echo $payload[OperatingSystemInfo::PLATFORM];   // linux
echo $payload[OperatingSystemInfo::CPU]['model_name'];
echo json_encode($payload, JSON_PRETTY_PRINT);



aragems\OsInfo\OsInfo;
use Laragems\OsInfo\OperatingSystemInfo;

$info = OsInfo::detect();
$payload = $info->toArray();

echo $payload[OperatingSystemInfo::PLATFORM];