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

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

paulm17/nats
============

A nats.io client in PHP

02PHP

Since Jun 17Pushed 5y ago1 watchersCompare

[ Source](https://github.com/paulm17/phpnats)[ Packagist](https://packagist.org/packages/paulm17/nats)[ RSS](/packages/paulm17-nats/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)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

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/387463?v=4)[Paul](/maintainers/paulm17)[@paulm17](https://github.com/paulm17)

---

Top Contributors

[![paulm17](https://avatars.githubusercontent.com/u/387463?v=4)](https://github.com/paulm17 "paulm17 (1 commits)")

### Embed Badge

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

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

###  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)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

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

78126.4M414](/packages/react-http)

PHPackages © 2026

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