承接 peterujah/php-cli-session 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

peterujah/php-cli-session

最新稳定版本:1.0.0

Composer 安装命令:

composer require peterujah/php-cli-session

包简介

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

README 文档

README

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

  • 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

Install via Composer PHP package manager.

composer require peterujah/php-cli-session

Usage

Initialize CLI streams

use Peterujah\Cli\System\Session;

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

Start PHP session with CLI-safe ID

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

See working example CLI Demos

Examples

Get CLI terminal info

$info = Session::getSystemInfo();

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

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

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

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

Methods Overview

Method Description
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

OS Status
Linux ✅ Tested
macOS ✅ Tested
Windows ✅ Tested
BSD/Unix ⚠️ Partial support
Docker ✅ Supported (if tput or stty available)

License

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

TODO

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

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固