PHPackages                             mschindler83/nats - 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. mschindler83/nats

ActiveLibrary

mschindler83/nats
=================

A nats.io client in PHP

2.2.5(4y ago)023MITPHPPHP ^7.1 || &gt;=8.0

Since Jun 28Pushed 4y agoCompare

[ Source](https://github.com/mschindler83/phpnats)[ Packagist](https://packagist.org/packages/mschindler83/nats)[ RSS](/packages/mschindler83-nats/feed)WikiDiscussions develop Synced 4w ago

READMEChangelog (1)Dependencies (4)Versions (36)Used By (0)

phpnats
=======

[](#phpnats)

Introduction
------------

[](#introduction)

A PHP client for the [NATS messaging system](https://nats.io). This fork of phpnats by repejota that supports more recent versions of NATS (2.2.0-beta) and contains little improvements to fit more into PHP7 world.

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

[](#requirements)

- php 7.1+
- [gnatsd](https://github.com/apcera/gnatsd)

Usage
-----

[](#usage)

### Installation

[](#installation)

Let's start by downloading composer into our project dir:

```
curl -O http://getcomposer.org/composer.phar
chmod +x composer.phar

```

Now let's tell composer about our project's dependancies, in this case, PHPNats. The way we do this is by creating a composer.json file, and placing it in the root folder of our project, right next to composer.phar

```
{
  "require": {
    "workfront/nats": "^2.2.3"
  }
}

```

Let's let Composer work its magic:

```
php composer.phar install

```

Composer will download all the dependencies defined in composer.json, and prepare all the files needed to autoload them.

### Basic Usage

[](#basic-usage)

```
$client = new \Nats\Connection();
$client->connect();

// Publish Subscribe

// Simple Subscriber.
$client->subscribe(
    'foo',
    function ($message) {
        printf("Data: %s\r\n", $message->getBody());
    }
);

// Simple Publisher.
$client->publish('foo', 'Marty McFly');

// Wait for 1 message.
$client->wait(1);

// Request Response

// Responding to requests.
$sid = $client->subscribe(
    'sayhello',
    function ($message) {
        $message->reply('Reply: Hello, '.$message->getBody().' !!!');
    }
);

// Request.
$client->request(
    'sayhello',
    'Marty McFly',
    function ($message) {
        echo $message->getBody();
    }
);
```

### Encoded Connections

[](#encoded-connections)

```
$encoder = new \Nats\Encoders\JSONEncoder();
$options = new \Nats\ConnectionOptions();
$client = new \Nats\EncodedConnection($options, $encoder);
$client->connect();

// Publish Subscribe

// Simple Subscriber.
$client->subscribe(
    'foo',
    function ($payload) {
        printf("Data: %s\r\n", $payload->getBody()[1]);
    }
);

// Simple Publisher.
$client->publish(
    'foo',
    [
     'Marty',
     'McFly',
    ]
);

// Wait for 1 message.
$client->wait(1);

// Request Response

// Responding to requests.
$sid = $client->subscribe(
    'sayhello',
    function ($message) {
        $message->reply('Reply: Hello, '.$message->getBody()[1].' !!!');
    }
);

// Request.
$client->request(
    'sayhello',
    [
     'Marty',
     'McFly',
    ],
    function ($message) {
        echo $message->getBody();
    }
);
```

Developer's Information
-----------------------

[](#developers-information)

### Releases

[](#releases)

- [Latest stable](https://github.com/Workfront/phpnats/tree/master)
- [Latest dev](https://github.com/Workfront/phpnats/tree/develop)
- [PHPNats on Packagist](https://packagist.org/packages/Workfront/phpnats)

### Tests

[](#tests)

Tests are in the `tests` folder. To run them, you need `PHPUnit` and execute `make test-tdd`.

We also have a BDD test suite under the `spec` folder. To run the suite, you need `PHPSpec` and execute `make test-bdd`.

You can also execute the all suites ( TDD + BDD ) with `make test`.

### Code Quality

[](#code-quality)

We are using [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer/docs)to ensure our code follow an high quality standard.

To perform an analysis of the code execute `make lint`.

There is currently three steps when we lint our code:

- First we lint with php itself `php -l`
- Then we lint with PSR2 standard
- And finally we lint with a custom [ruleset.xml](https://github.com/repejota/phpnats/blob/feature/lint-squiz/ruleset.xml) that checks dockblocks and different performance tips.

Creators
--------

[](#creators)

**Raül Pérez**

-
-

License
-------

[](#license)

MIT, see [LICENSE](LICENSE)

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 79.3% 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 ~70 days

Recently: every ~360 days

Total

32

Last Release

1776d ago

Major Versions

0.8.7 → 2.2.02020-02-27

PHP version history (2 changes)2.2.0PHP ^7.1

2.2.5PHP ^7.1 || &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4042f66ed6bd2585a8f7dc0e2a0fe78a78660ea4f5b4d5ced8663272d8b0bd71?d=identicon)[mschindler83](/maintainers/mschindler83)

---

Top Contributors

[![repejota](https://avatars.githubusercontent.com/u/36673?v=4)](https://github.com/repejota "repejota (284 commits)")[![dfeyer](https://avatars.githubusercontent.com/u/221173?v=4)](https://github.com/dfeyer "dfeyer (16 commits)")[![byrnedo](https://avatars.githubusercontent.com/u/5528491?v=4)](https://github.com/byrnedo "byrnedo (15 commits)")[![adriacidre](https://avatars.githubusercontent.com/u/593270?v=4)](https://github.com/adriacidre "adriacidre (12 commits)")[![irekk-wf](https://avatars.githubusercontent.com/u/61516173?v=4)](https://github.com/irekk-wf "irekk-wf (9 commits)")[![octante](https://avatars.githubusercontent.com/u/1949683?v=4)](https://github.com/octante "octante (6 commits)")[![josgilmo](https://avatars.githubusercontent.com/u/773565?v=4)](https://github.com/josgilmo "josgilmo (4 commits)")[![gorkaio](https://avatars.githubusercontent.com/u/4482916?v=4)](https://github.com/gorkaio "gorkaio (2 commits)")[![ingosus](https://avatars.githubusercontent.com/u/5129265?v=4)](https://github.com/ingosus "ingosus (2 commits)")[![netroby](https://avatars.githubusercontent.com/u/154278046?v=4)](https://github.com/netroby "netroby (1 commits)")[![olivermack](https://avatars.githubusercontent.com/u/666035?v=4)](https://github.com/olivermack "olivermack (1 commits)")[![omack](https://avatars.githubusercontent.com/u/1389984?v=4)](https://github.com/omack "omack (1 commits)")[![anthonysterling](https://avatars.githubusercontent.com/u/159960?v=4)](https://github.com/anthonysterling "anthonysterling (1 commits)")[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (1 commits)")[![ipadavic](https://avatars.githubusercontent.com/u/2059817?v=4)](https://github.com/ipadavic "ipadavic (1 commits)")[![xsuperbug](https://avatars.githubusercontent.com/u/7601737?v=4)](https://github.com/xsuperbug "xsuperbug (1 commits)")[![mschindler83](https://avatars.githubusercontent.com/u/2979969?v=4)](https://github.com/mschindler83 "mschindler83 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mschindler83-nats/health.svg)

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

PHPackages © 2026

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