PHPackages                             bitwasp/stratum - 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. bitwasp/stratum

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

bitwasp/stratum
===============

library for interfacing with stratum servers, used to serve both bitcoin mining and electrum clients

v0.3.0(10y ago)1928.3k—7.5%14[1 PRs](https://github.com/Bit-Wasp/stratum-php/pulls)PHP

Since May 16Pushed 8y ago6 watchersCompare

[ Source](https://github.com/Bit-Wasp/stratum-php)[ Packagist](https://packagist.org/packages/bitwasp/stratum)[ Docs](https://github.com/Bit-Wasp/stratum-php)[ RSS](/packages/bitwasp-stratum/feed)WikiDiscussions master Synced yesterday

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

stratum-php
-----------

[](#stratum-php)

[![Build Status](https://camo.githubusercontent.com/a228fad664a44605fa753a2a000cb7bac24a138e73fca52e35b303cac5b7493c/68747470733a2f2f7472617669732d63692e6f72672f4269742d576173702f7374726174756d2d7068702e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/Bit-Wasp/stratum-php)[![Code Coverage](https://camo.githubusercontent.com/1d1b4d9a4f8c866de964ecb865abb40713dc3a3fc23082e3e79de7e78ae37a12/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6269742d776173702f7374726174756d2d7068702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bit-wasp/stratum-php/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3c57f7045074bade600a4d017755f7cd78ae0957cacbee01a7a3db1e82686f29/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4269742d576173702f7374726174756d2d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Bit-Wasp/stratum-php/?branch=master)

Implementation of the Stratum protocol (for electrum and mining) using ReactPHP

### Client

[](#client)

The Client class is used to make a connection to a host. It takes a `ConnectorInterface`and `RequestFactory`.

`react/socket-client` provides a number of connectors, which can be combined to produce the desired functionality.

```
use \BitWasp\Stratum\Client;
use \BitWasp\Stratum\Connection;
use \BitWasp\Stratum\Request\RequestFactory;

$loop = \React\EventLoop\Factory::create();

$resolver = new \React\Dns\Resolver\Factory();

// Raw TCP, cannot perform DNS resolution
$tcp = new \React\SocketClient\TcpConnector($loop);

// TCP Connector with a DNS resolver
$dns = new \React\SocketClient\DnsConnector($tcp, $resolver->create('8.8.8.8', $loop));

// Encrypted connection
$context_options = [];

$tls = new \React\SocketClient\SecureConnector($dns, $loop, $context_options);

$requests = new RequestFactory;
$client = new Client($tls, $requests);

$host = '';
$port = '';

$client->connect($host, $port)->then(function (Connection $conn) {
    /* success */
}, function (\Exception $e) {
    /*  error  */
    print_r($e->getMessage());
});

$loop->run();
```

The SecureConnector initiates a TLS session to encrypt your connection. $context\_options is an optional value, but many Electrum servers have misconfigured SSL certificates! (incorrect CN field, or are self-signed) These will not be accepted with the default verification settings, and can be disabled by changing the $context\_options

```
$context_options = ["verify_name" => false, "allow_self_signed" => true];

```

### Connection

[](#connection)

A `Connection` represents a connection to a peer.

Requests can be sent to the peer using `Connection::request($method, $params = [])`, which returns a Promise for the pending result. When a response with the same ID is received, the promise will resolve this as the result.

```
$conn->request('server.banner')->then(function (Response $response) {
    print_r($response->getResult());
}, function (\Exception $e) {
    echo $e->getMessage();
});
```

`Request` instances can be sent using `Connection::sendRequest(Request $request)`which also returns a promise.

For a list of methods for the electrum and mining clients, see the respective Api classes. The constants are method's for these APIs.

```
$conn->sendRequest(new Request(null, 'server.banner'))->then(function (Response $response) {
    print_r($response->getResult());
}, function (\Exception $e) {
    echo $e->getMessage();
});
```

`NotificationInterface`'s can be sent using `Connection::sendNotify(NotificationInterface $note)`Notifications are not requests, and don't receive a response. This method is only relevant if using `Connection` from a servers perspective.

```
$conn->sendNotification(new NumBlocksNotification(123123));
```

#### Api's

[](#apis)

The Stratum protocol is implemented by electrum servers and stratum mining pools. Their methods are exposed by `ElectrumClient` and `MiningClient` respectively.

The api methods cause a Request to be sent, returning a promise to capture the result.

```
use \BitWasp\Stratum\Api\ElectrumClient;
use \BitWasp\Stratum\Client;
use \BitWasp\Stratum\Connection;
use \BitWasp\Stratum\Request\Response;
use \BitWasp\Stratum\Request\RequestFactory;

$loop = \React\EventLoop\Factory::create();
$tcp = new \React\SocketClient\TcpConnector($loop)   ;

$resolver = new \React\Dns\Resolver\Factory();
$dns = new \React\SocketClient\DnsConnector($tcp,$resolver->create('8.8.8.8', $loop));
$tls = new \React\SocketClient\SecureConnector($dns, $loop);
$requests = new RequestFactory;
$client = new Client($tls, $requests);

$host = 'anduck.net';
$port = 50002;
$client->connect($host, $port)->then(function (Connection $conn) {
    $electrum = new ElectrumClient($conn);
    $electrum->addressListUnspent('1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L')->then(function (Response $response) {
        print_r($response->getResult());
    });
}, function (\Exception $e) {
    echo 'error';
    echo $e->getMessage().PHP_EOL;
    /*  error  */
});

$loop->run();
```

#### Events

[](#events)

`Connection` emits a `message` event when a message is received which was not initiated by a Request. These messages are typically due to subscriptions.

The following events are emitted automatically by the library when encountered. The event name is the method used to enable the subscription.

- 'blockchain.headers.subscribe' emits a `HeadersNotification`
- 'blockchain.address.subscribe' emits a `AddressNotification`
- 'blockchain.numblocks.subscribe' emits a `NumBlocksNotification`
- 'mining.subscribe' emits a `MiningNotification`
- 'mining.set\_difficulty' emits a `SetDifficultyNotification`

```
use \BitWasp\Stratum\Api\ElectrumClient;
use \BitWasp\Stratum\Client;
use \BitWasp\Stratum\Connection;
use \BitWasp\Stratum\Notification\AddressNotification;
use \BitWasp\Stratum\Request\RequestFactory;

$loop = React\EventLoop\Factory::create();
$tcp = new \React\SocketClient\TcpConnector($loop);
$resolver = new \React\Dns\Resolver\Factory();
$dns = new \React\SocketClient\DnsConnector($tcp, $resolver->create('8.8.8.8', $loop));
$tls = new \React\SocketClient\SecureConnector($dns, $loop);

$requests = new RequestFactory;
$client = new Client($tls, $requests);

$host = 'anduck.net';
$port = 50002;
$client->connect($host, $port)->then(function (Connection $conn) {
    $conn->on('message', function ($message) {
        echo "Message received: ".PHP_EOL;
        print_r($message);
    });

    $conn->on(ElectrumClient::ADDRESS_SUBSCRIBE, function (AddressNotification $address) {
        echo "Received address update\n";
    });

    $electrum = new ElectrumClient($conn);
    $electrum->subscribeAddress('1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L')->then(function () {
        echo "subscribed\n";
    });
}, function (\Exception $e) {
    echo "ERROR: " . $e->getMessage().PHP_EOL;
});

$loop->run();
```

### Further Information

[](#further-information)

-
- [https://electrum.orain.org/wiki/Stratum\_protocol\_specification](https://electrum.orain.org/wiki/Stratum_protocol_specification)

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.4% 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 ~122 days

Total

4

Last Release

3699d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/763cdc5cc50414bacd4ff1080eede79432f7c3cc26a3d8aa9031b1537a8bd734?d=identicon)[thomaskerin](/maintainers/thomaskerin)

---

Top Contributors

[![afk11](https://avatars.githubusercontent.com/u/5617245?v=4)](https://github.com/afk11 "afk11 (17 commits)")[![DeftNerd](https://avatars.githubusercontent.com/u/3002275?v=4)](https://github.com/DeftNerd "DeftNerd (1 commits)")

### Embed Badge

![Health badge](/badges/bitwasp-stratum/health.svg)

```
[![Health](https://phpackages.com/badges/bitwasp-stratum/health.svg)](https://phpackages.com/packages/bitwasp-stratum)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M92](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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