PHPackages                             rmh-media/phpnats - 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. rmh-media/phpnats

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

rmh-media/phpnats
=================

A nats.io client in PHP

0.9.0(6y ago)06.7k1MITPHP

Since Jun 28Pushed 6y agoCompare

[ Source](https://github.com/rmh-media/phpnats)[ Packagist](https://packagist.org/packages/rmh-media/phpnats)[ RSS](/packages/rmh-media-phpnats/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (5)Versions (33)Used By (1)

phpnats
=======

[](#phpnats)

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

[](#introduction)

A PHP client for the [NATS messaging system](https://nats.io).

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

[](#requirements)

- php 5.6+
- [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": {
    "rmh-media/phpnats": "dev-master"
  }
}
```

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)

### 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 that checks dockblocks and different performance tips.

Creators
--------

[](#creators)

**Raül Pérez**

-
-

License
-------

[](#license)

MIT, see [LICENSE](LICENSE)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 81.1% 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 ~51 days

Recently: every ~206 days

Total

30

Last Release

2482d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/258ae6b3352c99dc9e4b0bdce5bc11c039a7a92ffb9218b48aea56622919a90f?d=identicon)[andreas-rmh](/maintainers/andreas-rmh)

---

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)")[![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)")[![andreas-rmh](https://avatars.githubusercontent.com/u/34645290?v=4)](https://github.com/andreas-rmh "andreas-rmh (2 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)")[![anthonysterling](https://avatars.githubusercontent.com/u/159960?v=4)](https://github.com/anthonysterling "anthonysterling (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)")[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (1 commits)")[![xsuperbug](https://avatars.githubusercontent.com/u/7601737?v=4)](https://github.com/xsuperbug "xsuperbug (1 commits)")[![ipadavic](https://avatars.githubusercontent.com/u/2059817?v=4)](https://github.com/ipadavic "ipadavic (1 commits)")[![netroby](https://avatars.githubusercontent.com/u/154278046?v=4)](https://github.com/netroby "netroby (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rmh-media-phpnats/health.svg)

```
[![Health](https://phpackages.com/badges/rmh-media-phpnats/health.svg)](https://phpackages.com/packages/rmh-media-phpnats)
```

###  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)[react/http

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

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)[friendsofsymfony/http-cache-bundle

Set path based HTTP cache headers and send invalidation requests to your HTTP cache

43813.2M47](/packages/friendsofsymfony-http-cache-bundle)

PHPackages © 2026

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