PHPackages                             itdesign-at/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. [HTTP &amp; Networking](/categories/http)
4. /
5. itdesign-at/nats

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

itdesign-at/nats
================

A nats.io client in PHP

0.8.7(7y ago)06MITPHP

Since Jun 28Pushed 2y agoCompare

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

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

phpnats
=======

[](#phpnats)

**Travis**

MasterDevelop[![Build Status](https://camo.githubusercontent.com/ecbd917736daecd0852ae8eade5c1f1efd927bc01e1e46693709234445789a38/68747470733a2f2f7472617669732d63692e6f72672f726570656a6f74612f7068706e6174732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/repejota/phpnats)[![Build Status](https://camo.githubusercontent.com/db88b1205d610eb9deece5be6772fb8405ae4b8da6f9fa9f5a34316ad1d0fdf7/68747470733a2f2f7472617669732d63692e6f72672f726570656a6f74612f7068706e6174732e706e673f6272616e63683d646576656c6f70)](https://travis-ci.org/repejota/phpnats)**Coverage**

MasterDevelop[![Coverage Status](https://camo.githubusercontent.com/c8084de83748fac6253eebd9f9d2e1ec7f72d1fcecc143c9a96736e7c966f184/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f726570656a6f74612f7068706e6174732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/repejota/phpnats?branch=master)[![Coverage Status](https://camo.githubusercontent.com/5c7e5420830210fbbc9d223fc31d941f5d120b66ed6cdb8f0097402842e6266a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f726570656a6f74612f7068706e6174732f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/r/repejota/phpnats?branch=develop)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": {
    "repejota/nats": "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)

### Releases

[](#releases)

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

### 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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 81.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 ~38 days

Recently: every ~103 days

Total

29

Last Release

2890d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2ff3fd51ea3dbf9fb1e2b2e2cdf6c8f3c549c06b1c96296fad300dfa04f2a4b?d=identicon)[andreas.kogelbauer](/maintainers/andreas.kogelbauer)

---

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)")[![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)")[![itd-kogelbauer](https://avatars.githubusercontent.com/u/100756038?v=4)](https://github.com/itd-kogelbauer "itd-kogelbauer (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M317](/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

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

PSR-18 and HTTPlug Async client with cURL

48247.0M382](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

83510.1M71](/packages/smi2-phpclickhouse)[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

24924.2M71](/packages/php-http-cache-plugin)

PHPackages © 2026

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