PHPackages                             dazzle-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. dazzle-php/ssh

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

dazzle-php/ssh
==============

Dazzle Asynchronous SSH.

v0.4.1(9y ago)119432[1 issues](https://github.com/dazzle-php/ssh/issues)1MITPHPPHP &gt;=5.6.7

Since May 7Pushed 8y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (5)Versions (5)Used By (1)

Dazzle Async SSH
================

[](#dazzle-async-ssh)

[![Build Status](https://camo.githubusercontent.com/5dff88cb665096bb79b3afe223a428aa8c0df1c54499093103c39dff2e90ddf8/68747470733a2f2f7472617669732d63692e6f72672f64617a7a6c652d7068702f7373682e737667)](https://travis-ci.org/dazzle-php/ssh)[![Code Coverage](https://camo.githubusercontent.com/fb542edb1128c9863b4bff676de1483ab871040e2f8a40cb072bd12d6d499967/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64617a7a6c652d7068702f7373682f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dazzle-php/ssh/?branch=master)[![Code Quality](https://camo.githubusercontent.com/2592fb0046c85fa72ab43c546ada1a975ca26c01397bdf90ef23e824585d3465/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64617a7a6c652d7068702f7373682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dazzle-php/ssh/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/1debc81832a693770b2d7102d8fc1679395778fea7fea2293f44c3292c90c50e/68747470733a2f2f706f7365722e707567782e6f72672f64617a7a6c652d7068702f7373682f762f737461626c65)](https://packagist.org/packages/dazzle-php/ssh)[![Latest Unstable Version](https://camo.githubusercontent.com/8ef07161e63f6d86bbdf611ea37c055fd41418f367bcc3cec0f05088fc7dc404/68747470733a2f2f706f7365722e707567782e6f72672f64617a7a6c652d7068702f7373682f762f756e737461626c65)](https://packagist.org/packages/dazzle-php/ssh)[![License](https://camo.githubusercontent.com/65ae1b971be6c896ce2c77f6ab627e366ca86832a4f5763d8f5b0951812b0a9c/68747470733a2f2f706f7365722e707567782e6f72672f64617a7a6c652d7068702f7373682f6c6963656e7365)](https://packagist.org/packages/dazzle-php/ssh/license)

> **Note:** This repository is part of [Dazzle Project](https://github.com/dazzle-php/dazzle) - the next-gen library for PHP. The project's purpose is to provide PHP developers with a set of complete tools to build functional async applications. Please, make sure you read the attached README carefully and it is guaranteed you will be surprised how easy to use and powerful it is. In the meantime, you might want to check out the rest of our async libraries in [Dazzle repository](https://github.com/dazzle-php) for the full extent of Dazzle experience.

[![](https://raw.githubusercontent.com/dazzle-php/dazzle/master/media/dazzle-x125.png)](https://raw.githubusercontent.com/dazzle-php/dazzle/master/media/dazzle-x125.png)

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

[](#description)

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

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

[](#feature-highlights)

Dazzle SSH features:

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

Provided Example(s)
-------------------

[](#provided-examples)

### 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 = [ "DAZZLE\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**.

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

[](#requirements)

Dazzle SSH requires:

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

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

[](#installation)

To install this library make sure you have [composer](https://getcomposer.org/) installed, then run following command:

```
$> composer require dazzle-php/ssh

```

Tests
-----

[](#tests)

Tests can be run via:

```
$> vendor/bin/phpunit -d memory_limit=1024M

```

Versioning
----------

[](#versioning)

Versioning of Dazzle libraries is being shared between all packages included in [Dazzle Project](https://github.com/dazzle-php/dazzle). That means the releases are being made concurrently for all of them. On one hand this might lead to "empty" releases for some packages at times, but don't worry. In the end it is far much easier for contributors to maintain and -- what's the most important -- much more straight-forward for users to understand the compatibility and inter-operability of the packages.

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

[](#contributing)

Thank you for considering contributing to this repository!

- The contribution guide can be found in the [contribution tips](https://github.com/dazzle-php/ssh/blob/master/CONTRIBUTING.md).
- Open tickets can be found in [issues section](https://github.com/dazzle-php/ssh/issues).
- Current contributors are listed in [graphs section](https://github.com/dazzle-php/ssh/graphs/contributors)
- To contact the author(s) see the information attached in [composer.json](https://github.com/dazzle-php/ssh/blob/master/composer.json) file.

License
-------

[](#license)

Dazzle SSH is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

---

*"Everything is possible. The impossible just takes longer."* ― Dan Brown

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

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

Total

4

Last Release

3293d 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 (17 commits)")

---

Tags

asyncdazzlephpphp-libphp7sshssh2asyncasynchronoussshdriverssh2krakenkraken-php

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/dazzle-php-ssh/health.svg)](https://phpackages.com/packages/dazzle-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)
