PHPackages                             savvii/ssh-tunnel - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. savvii/ssh-tunnel

ActiveLibrary[HTTP &amp; Networking](/categories/http)

savvii/ssh-tunnel
=================

Small library to create an SSH tunnel, for example for MySQL

1.1.2(3y ago)41.8k↓50%2MITPHPPHP &gt;=8.0

Since Mar 8Pushed 3y ago4 watchersCompare

[ Source](https://github.com/Savvii/ssh-tunnel)[ Packagist](https://packagist.org/packages/savvii/ssh-tunnel)[ RSS](/packages/savvii-ssh-tunnel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (6)Used By (0)

[![Code Quality](https://github.com/Savvii/ssh-tunnel/actions/workflows/codeQuality.yml/badge.svg)](https://github.com/Savvii/ssh-tunnel/actions/workflows/codeQuality.yml)

Small library to create a SSH Tunnel
------------------------------------

[](#small-library-to-create-a-ssh-tunnel)

Example usage:

```
use Savvii\SshTunnel\SshTunnel;

$tunnel = new SshTunnel(
    sshUsername: 'myuser',
    sshHost: 'jumpserver.example.com',
    sshPort: 22,
    bindHost: 'remote-db-host.local.lan',
    bindPort: 3306
);

$db = new PDO(
    sprintf(
        "mysql:host=%s;port=%d",
        $tunnel->localAddress,
        $tunnel->localPort
    )
);
```

When the PHP script ends or the `SshTunnel` object is destroyed the SSH tunnel is disconnected.

### Warning

[](#warning)

When you create the object but let it go out of scope, by default the SSH tunnel will be cleaned up. This will not work:

```
function connect(): void
{
    $tunnel = new SshTunnel(...);
}

connect();
// At this point the SSH tunnel is disconnected because $tunnel went out of scope.
```

This will work:

```
function connect(): void
{
    return new SshTunnel(...);
}

$tunnel = connect();
// At this point the SSH tunnel works.
```

If you are creating the `SshTunnel` object in the constructor of a class, make sure to store it in a class property, to make it not go out of scope when the constructor is finished.

Requirements
------------

[](#requirements)

- Linux, MacOS or FreeBSD
- PHP 8.0 or greater
- PHP functions `proc_open`,`proc_close`,`proc_terminate` and `proc_get_status` enabled
- Binary `ssh`
- Binary `lsof`, used by default but can be skipped.
- Binary `nc`, used by default but can be skipped.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Every ~0 days

Total

4

Last Release

1163d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/74e812365e87e0f9460a2f9d24d9ff15a892d108730605fad8ef1853a3cb41b2?d=identicon)[jeroenvermeulen](/maintainers/jeroenvermeulen)

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/savvii-ssh-tunnel/health.svg)

```
[![Health](https://phpackages.com/badges/savvii-ssh-tunnel/health.svg)](https://phpackages.com/packages/savvii-ssh-tunnel)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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