PHPackages                             kraken-php/ssh - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. kraken-php/ssh

ActiveLibrary[Queues &amp; Workers](/categories/queues)

kraken-php/ssh
==============

Kraken Asynchronous SSH.

v0.4.1(9y ago)222MITPHPPHP &gt;=5.6.7

Since May 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/kraken-php/ssh)[ Packagist](https://packagist.org/packages/kraken-php/ssh)[ Docs](http://kraken-php.com)[ RSS](/packages/kraken-php-ssh/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

Kraken Asynchronous SSH
=======================

[](#kraken-asynchronous-ssh)

[![Build Status](https://camo.githubusercontent.com/af15010c36476fc4e6c49984421bf2b84750be2adc45fc8bebf1b90d9a7b52c3/68747470733a2f2f7472617669732d63692e6f72672f6b72616b656e2d7068702f6672616d65776f726b2e737667)](https://travis-ci.org/kraken-php/framework)[![Latest Stable Version](https://camo.githubusercontent.com/c3ddcb85300b9ecdb9db9bfe80c7da9d729c4d40572cf2a1a83d9512b9cf8d55/68747470733a2f2f706f7365722e707567782e6f72672f6b72616b656e2d7068702f7373682f762f737461626c65)](https://packagist.org/packages/kraken-php/ssh)[![Latest Unstable Version](https://camo.githubusercontent.com/1f29dc46f9b299b7abb0d0655a73b06dc022cd7e60fdbbef18140a83f94d6df2/68747470733a2f2f706f7365722e707567782e6f72672f6b72616b656e2d7068702f7373682f762f756e737461626c65)](https://packagist.org/packages/kraken-php/ssh)[![License](https://camo.githubusercontent.com/7b3d640f212d4ca5dfa30751f70cef9fd309f7b19fdd33448b776f26fdfdd42f/68747470733a2f2f706f7365722e707567782e6f72672f6b72616b656e2d7068702f6672616d65776f726b2f6c6963656e7365)](https://packagist.org/packages/kraken-php/framework)[![Kraken Compatible](https://camo.githubusercontent.com/1b4bd0ba007b4666bb6e1a081a7aeeafd8c9cfcaeab74fc4121ac3e353e3b51f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6b72616b656e2d636f6d70617469626c652d3662303261662e737667)](https://github.com/kraken-php/framework)

> **Note:** This repository is a part of [Kraken Framework](https://github.com/kraken-php/framework), but **can be used freely as standalone library**. If you are interested in more asynchronous components for PHP, check out the rest of [Kraken Project](https://github.com/kraken-php) or see our [asynchronous application skeleton](https://github.com/kraken-php/kraken) example.

Description
-----------

[](#description)

SSH is a component that provides consistent interface for PHP SSH2 extension and allows asynchronous writing and reading.

Feature Highlights
------------------

[](#feature-highlights)

SSH features:

- OOP abstraction for PHP SSH2 extension,
- Support for variety of authorization methods,
- Asynchronous SSH2 commands,
- Asynchronous operations on files via SFTP,
- Kraken Framework compatibility,
- ...and more.

Examples
--------

[](#examples)

This section contains most frequently asked for examples. You can see more in **example directory** or in [official documentation](http://kraken-php.com/docs/api-ssh).

### Executing commands

[](#executing-commands)

```
$loop   = new Loop(new SelectLoop);
$auth   = new SSH2Password($user, $pass);
$config = new SSH2Config();
$ssh2   = new SSH2($auth, $config, $loop);

$ssh2->on('connect:shell', function(SSH2DriverInterface $shell) use($ssh2, $loop) {
    echo "# CONNECTED SHELL\n";

    $buffer = '';
    $command = $shell->open();
    $command->write('ls -la');
    $command->on('data', function(SSH2ResourceInterface $command, $data) use(&$buffer) {
        $buffer .= $data;
    });
    $command->on('end', function(SSH2ResourceInterface $command) use(&$buffer) {
        echo "# COMMAND RETURNED:\n";
        echo $buffer;
        $command->close();
    });
    $command->on('close', function(SSH2ResourceInterface $command) use($shell) {
        $shell->disconnect();
    });
});

$ssh2->on('disconnect:shell', function(SSH2DriverInterface $shell) use($ssh2) {
    echo "# DISCONNECTED SHELL\n";
    $ssh2->disconnect();
});

$ssh2->on('connect', function(SSH2Interface $ssh2) {
    echo "# CONNECTED\n";
    $ssh2->createDriver(SSH2::DRIVER_SHELL)
         ->connect();
});

$ssh2->on('disconnect', function(SSH2Interface $ssh2) use($loop) {
    echo "# DISCONNECTED\n";
    $loop->stop();
});

$loop->onTick(function() use($ssh2) {
    $ssh2->connect();
});

$loop->start();
```

### Writing files

[](#writing-files)

```
$loop   = new Loop(new SelectLoop);
$auth   = new SSH2Password($user, $pass);
$config = new SSH2Config();
$ssh2   = new SSH2($auth, $config, $loop);

$ssh2->on('connect:sftp', function(SSH2DriverInterface $sftp) use($loop, $ssh2) {
    echo "# CONNECTED SFTP\n";

    $lines = [ "KRAKEN\n", "IS\n", "AWESOME!\n" ];
    $linesPointer = 0;

    $file = $sftp->open(__DIR__ . '/_file_write.txt', 'w+');
    $file->write();
    $file->on('drain', function(SSH2ResourceInterface $file) use(&$lines, &$linesPointer) {
        echo "# PART OF THE DATA HAS BEEN WRITTEN\n";
        if ($linesPointer < count($lines)) {
            $file->write($lines[$linesPointer++]);
        }
    });
    $file->on('finish', function(SSH2ResourceInterface $file) {
        echo "# FINISHED WRITING\n";
        $file->close();
    });
    $file->on('close', function(SSH2ResourceInterface $file) use($sftp) {
        echo "# FILE HAS BEEN CLOSED\n";
        $sftp->disconnect();
    });
});

$ssh2->on('disconnect:sftp', function(SSH2DriverInterface $sftp) use($ssh2) {
    echo "# DISCONNECTED SFTP\n";
    $ssh2->disconnect();
});

$ssh2->on('connect', function(SSH2Interface $ssh2) {
    echo "# CONNECTED\n";
    $ssh2->createDriver(SSH2::DRIVER_SFTP)
         ->connect();
});

$ssh2->on('disconnect', function(SSH2Interface $ssh2) use($loop) {
    echo "# DISCONNECTED\n";
    $loop->stop();
});

$loop->onTick(function() use($ssh2) {
    $ssh2->connect();
});

$loop->start();
```

### Reading files

[](#reading-files)

```
$loop   = new Loop(new SelectLoop);
$auth   = new SSH2Password($user, $pass);
$config = new SSH2Config();
$ssh2   = new SSH2($auth, $config, $loop);

$ssh2->on('connect:sftp', function(SSH2DriverInterface $sftp) use($loop, $ssh2) {
    echo "# CONNECTED SFTP\n";

    $buffer = '';
    $file = $sftp->open(__DIR__ . '/_file_read.txt', 'r+');
    $file->read();
    $file->on('data', function(SSH2ResourceInterface $file, $data) use(&$buffer) {
        $buffer .= $data;
    });
    $file->on('end', function(SSH2ResourceInterface $file) use(&$buffer) {
        echo "# FOLLOWING LINES WERE READ FROM FILE:\n";
        echo $buffer;
        $file->close();
    });
    $file->on('close', function(SSH2ResourceInterface $file) use($sftp) {
        echo "# FILE HAS BEEN CLOSED\n";
        $sftp->disconnect();
    });
});

$ssh2->on('disconnect:sftp', function(SSH2DriverInterface $sftp) use($ssh2) {
    echo "# DISCONNECTED SFTP\n";
    $ssh2->disconnect();
});

$ssh2->on('connect', function(SSH2Interface $ssh2) {
    echo "# CONNECTED\n";
    $ssh2->createDriver(SSH2::DRIVER_SFTP)
         ->connect();
});

$ssh2->on('disconnect', function(SSH2Interface $ssh2) use($loop) {
    echo "# DISCONNECTED\n";
    $loop->stop();
});

$loop->onTick(function() use($ssh2) {
    $ssh2->connect();
});

$loop->start();
```

See more examples in **example directory** or in [official documentation](http://kraken-php.com/docs/api-ssh).

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

[](#requirements)

- PHP-5.6 or PHP-7.0+,
- UNIX or Windows OS,
- PHP SSH2 extension enabled.

Installation
------------

[](#installation)

```
composer require kraken-php/ssh

```

Tests
-----

[](#tests)

Tests are provided within our write-only [Framework repository](https://github.com/kraken-php/framework).

Documentation
-------------

[](#documentation)

Documentation for this module can be found in the [official documentation](http://kraken-php.com/docs/api-ssh).

Contributing
------------

[](#contributing)

This library is read-only subtree split of Kraken Framework. To make contributions, please go to [Framework repository](https://github.com/kraken-php/framework).

License
-------

[](#license)

This library licensed under the MIT license, see more information in [Kraken Framework](https://github.com/kraken-php/framework) license section.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~2 days

Total

3

Last Release

3337d ago

PHP version history (2 changes)v0.4.0PHP &gt;=5.5.9

0.4.x-devPHP &gt;=5.6.7

### Community

Maintainers

![](https://www.gravatar.com/avatar/edd40f7be77d3f9934f998dc0859d0562e42c715d61f5139feaf948a2fcb6050?d=identicon)[khelle](/maintainers/khelle)

---

Top Contributors

[![khelle](https://avatars.githubusercontent.com/u/5642657?v=4)](https://github.com/khelle "khelle (9 commits)")

---

Tags

asyncasynchronoussshdriverssh2krakenkraken-php

### Embed Badge

![Health badge](/badges/kraken-php-ssh/health.svg)

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

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k130.2M409](/packages/amphp-amp)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

92550.1M208](/packages/revolt-event-loop)[amphp/parallel

Parallel processing component for Amp.

85249.9M91](/packages/amphp-parallel)[amphp/sync

Non-blocking synchronization primitives for PHP based on Amp and Revolt.

19158.1M51](/packages/amphp-sync)[amphp/serialization

Serialization tools for IPC and data storage in PHP.

13656.4M20](/packages/amphp-serialization)[recoil/react

Integrate Recoil with ReactPHP.

32286.7k12](/packages/recoil-react)

PHPackages © 2026

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