adachsoft/ssh-gate
Composer 安装命令:
composer require adachsoft/ssh-gate
包简介
SSH Gate library
关键字:
README 文档
README
A clean, type-safe PHP library for SSH account management, sessions and remote command execution.
adachsoft/ssh-gate provides a high-level Facade + Builder pattern with strongly typed collections powered by adachsoft/collection.
Features
- Full SSH account CRUD operations
- Login / logout session management
- Remote SSH command execution via dedicated API
- Optional per-command timeout (in milliseconds) for remote execution
- Strongly typed immutable collections (
SshAccountCollection,SshSessionCollection) - Easy configuration via
SshModuleFacadeBuilder - Interactive CLI with colored output and icons
- Comprehensive exception handling (
SshModuleException,SshAccountNotFoundException) - Fully tested with PHPUnit + PHPStan ready
Requirements
- PHP 8.3+
adachsoft/collection:^3.0guzzlehttp/guzzle:^7.8adachsoft/console-io:^0.2(for CLI)adachsoft/console-internal:^0.1(for CLI)
Installation
composer require adachsoft/ssh-gate
After installation the CLI binary will be available via Composer.
Quick Start - Public API
Creating the Facade
use AdachSoft\SshGate\PublicApi\Builder\SshModuleFacadeBuilder;
$facade = (new SshModuleFacadeBuilder())
->useJsonAccountRepository(__DIR__ . '/ssh-accounts.json')
->withSshApiBaseUrl('https://ssh-api.yourproject.com')
->build();
Basic Usage
// Add account
$facade->addAccount(new AddSshAccountRequest(
name: 'Production Server',
host: 'prod.example.com',
port: 22,
username: 'deploy',
password: 'super-secret-pass',
));
// Login
$loginResponse = $facade->login(new SshLoginRequest(accountId: 'abc123'));
// Execute command with optional timeout (in milliseconds)
$commandResponse = $facade->executeCommand(
new SshCommandRequest(
command: 'ls -la /var/www',
sessionToken: $loginResponse->sessionToken,
timeout: 5000, // 5 seconds
),
);
echo $commandResponse->stdout;
// List accounts
$accountsResponse = $facade->listAccounts();
foreach ($accountsResponse->accounts as $account) {
echo $account->name . ' @ ' . $account->host . PHP_EOL;
}
Command timeouts
SshCommandRequest accepts an optional timeout parameter (in milliseconds). When provided, it is forwarded to the underlying HTTP SSH API (/execute-remote). When omitted (null), the server-side default timeout is used.
CLI Usage
The library includes an interactive CLI powered by adachsoft/console-internal and adachsoft/console-io (colored output with icons).
Running the CLI
# After composer install
php bin/ssh-gate
# Or via Composer bin (if configured in your project)
vendor/bin/ssh-gate
Available Commands
All commands are prefixed with \:
\help– List all available commands\addor\add account– Interactively add a new SSH account (prompts for name, host, port, username, password)\listor\ls– List all configured SSH accounts\exit– Exit the interactive session
Example Session
$ php bin/ssh-gate
🚀 SSH Gate CLI started. Type \help for available commands.
> \add
Enter account name: prod-server
Enter host (e.g., example.com or IP): prod.example.com
Enter port (default 22): [22]
Enter username: deploy
Enter password (leave empty if none or using key):
✅ SSH account 'prod-server' added successfully.
> \ls
Configured SSH Accounts:
- ID: abc123, Name: prod-server, Host: prod.example.com, User: deploy, Port: 22
> \exit
The CLI uses ColoredCliOutput + IconCliOutput for nice terminal output with colors and Unicode icons.
Main Components
SshModuleFacadeInterface
The main entry point of the library. See detailed documentation directly in:
src/PublicApi/Facade/SshModuleFacadeInterface.php
Builder
SshModuleFacadeBuilder allows you to configure:
useJsonAccountRepository(string $path)– recommended JSON storagewithSshApiBaseUrl(string $baseUrl)– base URL of your SSH API- Custom implementations via
with*Api()andwithAccountRepository()
Collections
Both collections extend AdachSoft\Collection\AbstractImmutableCollection and use isValidItem() for strict type validation.
SshAccountCollectionSshSessionCollection
DTOs, Requests & Responses
All value objects, requests and responses are located in the AdachSoft\SshGate\PublicApi\* namespace.
Testing
composer test
# or
vendor/bin/phpunit
Static Analysis & Coding Style
composer phpstan
composer csfix
License
MIT License – see the LICENSE file for details.
Author
Arkadiusz Adach – AdachSoft
Development Notes:
listSessions()currently returns an empty collection (placeholder for future API integration).- The library is fully tested (91 tests, 324 assertions).
- PHPDoc is written in English as per project standards.
adachsoft/ssh-gate 适用场景与选型建议
adachsoft/ssh-gate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ssh」 「gateway」 「adachsoft」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/ssh-gate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/ssh-gate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/ssh-gate 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
Altax is an extensible deployment tool for PHP.
Cisco IOS communications and configuration parsing library
Client library to send SMS using Comilio SMS Gateway API (https://www.comilio.it)
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-20