clue/reactphp-ssh-proxy
Async SSH proxy connector/forwarder for ReactPHP. Tunnel any TCP/IP protocol (HTTP, SMTP, IMAP, databases) through an SSH server using the system ssh binary. Implements ReactPHP ConnectorInterface for drop-in use with existing clients.
Start by installing via Composer (composer require clue/ssh-proxy) and reviewing the examples in the repo’s examples/ directory—especially connect.php and port-forward.php. The core use case is tunneling traffic to internal services (e.g., databases, internal APIs) through an SSH jump host without blocking the ReactPHP event loop. For example, to connect to a MySQL database behind a firewall:
$loop = React\EventLoop\Factory::create();
$factory = new Clue\React\SshProxy\Factory($loop);
// Connect to SSH jump host
$factory->connect('user@jump-host.example.com', [
'password' => 'secret', // or 'privateKey' => file_get_contents('~/.ssh/id_rsa')
])->then(function (Clue\React\SshProxy\Proxy $proxy) use ($loop) {
// Use proxy to forward traffic to internal MySQL
$proxy->createConnector()->connect('127.0.0.1:3306')
->then(function (React\Socket\ConnectionInterface $dbConn) {
// Use $dbConn like any normal socket connection
});
});
$loop->run();
First look at: README, examples/connect.php, and the Proxy class API.
Proxy::createConnector() to create a React Socket Connector that wraps SSH. Feed this into React’s Client, DbalConnector, or HTTP clients.
$connector = $proxy->createConnector();
new React\Http\Client($connector, $loop);
Stream APIs—ideal for building CLI tools or proxies.react/socket, react/http, or thiagoalessio/tesseract_for_php to build SSH-tunneled logging or monitoring agents.Integration tip: Hook into SshConnection events (e.g., error, close) via the factory callback to implement reconnection logic.
'privateKey') over passwords—passwords are not deferred; they block during auth negotiation unless you use callback-based auth (rare).React\Promise\RejectedPromise, not exceptions in callbacks—always handle with .catch().$conn->close() to avoid leaks.drain. Use once($stream, 'drain') before bulk writes.phpseclib/phpseclib. Ensure ext-openssl or ext-gmp is available for crypto.timeout in the factory options (default is 10s)—critical for reliable long-running connections.Extension point: Extend Proxy to add custom keep-alive logic or per-session logging via decorators.
How can I help you explore Laravel packages today?