{"id":30116347,"url":"https://github.com/peterujah/php-cli-session","last_synced_at":"2025-08-10T09:11:26.467Z","repository":{"id":306583680,"uuid":"1026662189","full_name":"peterujah/php-cli-session","owner":"peterujah","description":"A lightweight utility class to manage and inspect CLI session environments in PHP.","archived":false,"fork":false,"pushed_at":"2025-07-26T11:44:40.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-26T16:43:56.411Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterujah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-26T10:50:56.000Z","updated_at":"2025-07-26T11:37:23.000Z","dependencies_parsed_at":"2025-07-26T16:44:01.417Z","dependency_job_id":"ebfd7525-fce9-4213-b142-84e972bfd06d","html_url":"https://github.com/peterujah/php-cli-session","commit_stats":null,"previous_names":["peterujah/php-cli-session"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/peterujah/php-cli-session","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-cli-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-cli-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-cli-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-cli-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterujah","download_url":"https://codeload.github.com/peterujah/php-cli-session/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-cli-session/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269699928,"owners_count":24461269,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-08-10T09:11:25.630Z","updated_at":"2025-08-10T09:11:26.444Z","avatar_url":"https://github.com/peterujah.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CLI Session Helper for PHP\n\nA lightweight utility class to manage and inspect CLI session environments in PHP.  \nDesigned for cross-platform compatibility (Linux, macOS, Windows) with focus on stream handling, session identification, terminal capability detection, and environmental diagnostics.\n\n\u003e No external dependencies. Built for PHP 7+\n\n---\n\n## Features\n\n- Detects and resolves `STDIN`, `STDOUT`, `STDERR` in CLI environments\n- Handles platform-specific stream opening safely\n- Retrieves:\n  - Terminal size (height and width)\n  - Current user (`whoami`)\n  - MAC address\n  - OS and system model\n  - Shell and terminal name\n- Detects:\n  - ANSI and color support\n  - Platform type (Windows, macOS, Linux, cloud)\n- Generates a **unique system identifier** for CLI sessions\n- Silently handles errors using proper fallbacks\n\n---\n\n## Installation\n\nInstall via Composer PHP package manager.\n\n```bash\ncomposer require peterujah/php-cli-session\n```\n\n---\n\n## Usage\n\n### Initialize CLI streams\n\n```php\nuse Peterujah\\Cli\\System\\Session;\n\nSession::init(); // Optional if constructor is called\n```\n\n### Start PHP session with CLI-safe ID\n\n```php\n$sessionId = Session::getSystemId();\nsession_id($sessionId);\nsession_start();\n```\n\nSee working example [CLI Demos](https://github.com/peterujah/php-cli-session/tree/main/tests)\n\n---\n\n## Examples\n\n### Get CLI terminal info\n\n```php\n$info = Session::getSystemInfo();\n\nforeach ($info as $item) {\n    echo $item['Name'] . ': ' . $item['Value'] . PHP_EOL;\n}\n```\n\n### Detect color and ANSI support\n\n```php\nif (Session::isColorSupported()) {\n    echo \"✅ Color output is supported.\" . PHP_EOL;\n}\n\nif (Session::isAnsiSupported()) {\n    echo \"✅ ANSI escape sequences are supported.\" . PHP_EOL;\n}\n```\n\n### Detect terminal dimensions\n\n```php\n$width = Session::getWidth();\n$height = Session::getHeight();\n\necho \"Terminal Size: {$width} x {$height}\" . PHP_EOL;\n```\n\n---\n\n## Methods Overview\n\n| Method                       | Description                                                    |\n| ---------------------------- | -------------------------------------------------------------- |\n| `init()`                     | Initializes CLI stream resources (`STDIN`, `STDOUT`, etc.)     |\n| `getSystemId()`              | Returns a unique, hash-based identifier for the current system |\n| `getSystemInfo()`            | Returns structured system diagnostics                          |\n| `getTerminalName()`          | Returns terminal name (`tty`, PowerShell, etc.)                |\n| `getMacAddress()`            | Retrieves system MAC address                                   |\n| `getPid()`                   | Gets the parent process ID                                     |\n| `whoami()`                   | Gets the current user executing the script                     |\n| `isColorSupported()`         | Checks if terminal supports color output                       |\n| `isAnsiSupported()`          | Checks if terminal supports ANSI escape codes                  |\n| `getWidth()` / `getHeight()` | Gets terminal width and height                                 |\n| `isPlatform($os)`            | Checks for OS platform or cloud environment                    |\n\n---\n\n## Platform Compatibility\n\n| OS       | Status                                       |\n| -------- | -------------------------------------------- |\n| Linux    | ✅ Tested                                    |\n| macOS    | ✅ Tested                                    |\n| Windows  | ✅ Tested                                    |\n| BSD/Unix | ⚠️ Partial support                           |\n| Docker   | ✅ Supported (if `tput` or `stty` available) |\n\n---\n\n## License\n\nMIT License — use it, hack it, extend it.\n\n---\n\n## TODO\n\n* Optional support for logging output to a file\n* Add unit tests\n* CLI command wrapper integration\n* PHP framework integration hook\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-cli-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterujah%2Fphp-cli-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-cli-session/lists"}