PHPackages                             peterujah/php-cli-session - 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. [CLI &amp; Console](/categories/cli)
4. /
5. peterujah/php-cli-session

ActiveLibrary[CLI &amp; Console](/categories/cli)

peterujah/php-cli-session
=========================

A PHP library for managing and inspecting CLI session environments across platforms.

1.0.0(9mo ago)04MITPHPPHP ^7.4 || ^8.0

Since Jul 26Pushed 9mo agoCompare

[ Source](https://github.com/peterujah/php-cli-session)[ Packagist](https://packagist.org/packages/peterujah/php-cli-session)[ RSS](/packages/peterujah-php-cli-session/feed)WikiDiscussions main Synced 1mo ago

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

CLI Session Helper for PHP
==========================

[](#cli-session-helper-for-php)

A lightweight utility class to manage and inspect CLI session environments in PHP.
Designed for cross-platform compatibility (Linux, macOS, Windows) with focus on stream handling, session identification, terminal capability detection, and environmental diagnostics.

> No external dependencies. Built for PHP 7+

---

Features
--------

[](#features)

- Detects and resolves `STDIN`, `STDOUT`, `STDERR` in CLI environments
- Handles platform-specific stream opening safely
- Retrieves:
    - Terminal size (height and width)
    - Current user (`whoami`)
    - MAC address
    - OS and system model
    - Shell and terminal name
- Detects:
    - ANSI and color support
    - Platform type (Windows, macOS, Linux, cloud)
- Generates a **unique system identifier** for CLI sessions
- Silently handles errors using proper fallbacks

---

Installation
------------

[](#installation)

Install via Composer PHP package manager.

```
composer require peterujah/php-cli-session
```

---

Usage
-----

[](#usage)

### Initialize CLI streams

[](#initialize-cli-streams)

```
use Peterujah\Cli\System\Session;

Session::init(); // Optional if constructor is called
```

### Start PHP session with CLI-safe ID

[](#start-php-session-with-cli-safe-id)

```
$sessionId = Session::getSystemId();
session_id($sessionId);
session_start();
```

See working example [CLI Demos](https://github.com/peterujah/php-cli-session/tree/main/tests)

---

Examples
--------

[](#examples)

### Get CLI terminal info

[](#get-cli-terminal-info)

```
$info = Session::getSystemInfo();

foreach ($info as $item) {
    echo $item['Name'] . ': ' . $item['Value'] . PHP_EOL;
}
```

### Detect color and ANSI support

[](#detect-color-and-ansi-support)

```
if (Session::isColorSupported()) {
    echo "✅ Color output is supported." . PHP_EOL;
}

if (Session::isAnsiSupported()) {
    echo "✅ ANSI escape sequences are supported." . PHP_EOL;
}
```

### Detect terminal dimensions

[](#detect-terminal-dimensions)

```
$width = Session::getWidth();
$height = Session::getHeight();

echo "Terminal Size: {$width} x {$height}" . PHP_EOL;
```

---

Methods Overview
----------------

[](#methods-overview)

MethodDescription`init()`Initializes CLI stream resources (`STDIN`, `STDOUT`, etc.)`getSystemId()`Returns a unique, hash-based identifier for the current system`getSystemInfo()`Returns structured system diagnostics`getTerminalName()`Returns terminal name (`tty`, PowerShell, etc.)`getMacAddress()`Retrieves system MAC address`getPid()`Gets the parent process ID`whoami()`Gets the current user executing the script`isColorSupported()`Checks if terminal supports color output`isAnsiSupported()`Checks if terminal supports ANSI escape codes`getWidth()` / `getHeight()`Gets terminal width and height`isPlatform($os)`Checks for OS platform or cloud environment---

Platform Compatibility
----------------------

[](#platform-compatibility)

OSStatusLinux✅ TestedmacOS✅ TestedWindows✅ TestedBSD/Unix⚠️ Partial supportDocker✅ Supported (if `tput` or `stty` available)---

License
-------

[](#license)

MIT License — use it, hack it, extend it.

---

TODO
----

[](#todo)

- Optional support for logging output to a file
- Add unit tests
- CLI command wrapper integration
- PHP framework integration hook

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance55

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Unknown

Total

1

Last Release

296d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce34af529a4ed50696211a2b4d330fbadd2d1738bc5d010523eb4a85cf342b17?d=identicon)[peterujah](/maintainers/peterujah)

---

Top Contributors

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

---

Tags

phpclicommand-lineterminalshellcolorsessionansisystem infophp-streamphp cli tools

### Embed Badge

![Health badge](/badges/peterujah-php-cli-session/health.svg)

```
[![Health](https://phpackages.com/badges/peterujah-php-cli-session/health.svg)](https://phpackages.com/packages/peterujah-php-cli-session)
```

###  Alternatives

[alecrabbit/php-console-spinner

Extremely flexible spinner for \[async\] php cli applications

24032.0k2](/packages/alecrabbit-php-console-spinner)[nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2582.1M11](/packages/nunomaduro-laravel-console-task)[bvanhoekelen/terminal-style

Return your terminal message in style! Change the text style, text color and text background color form the terminal interface with ANSI color codes. The terminal style tool support Laravel and Composer.

19784.4k2](/packages/bvanhoekelen-terminal-style)[alecrabbit/php-cli-snake

Lightweight cli spinner with zero dependencies

29211.3k5](/packages/alecrabbit-php-cli-snake)[php-school/learn-you-php

An introduction to PHP's core features: i/o, http, arrays, exceptions and so on.

3192.0k](/packages/php-school-learn-you-php)

PHPackages © 2026

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