PHPackages                             vladitot/phpnats2 - 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. vladitot/phpnats2

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

vladitot/phpnats2
=================

A nats.io client in PHP

v1.0.19(6y ago)18.4kMITPHP

Since May 7Pushed 6y ago2 watchersCompare

[ Source](https://github.com/vladitot/phpnats2)[ Packagist](https://packagist.org/packages/vladitot/phpnats2)[ RSS](/packages/vladitot-phpnats2/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (6)Versions (22)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

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 77.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 ~28 days

Recently: every ~104 days

Total

20

Last Release

2401d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e96aecfecf14f6334f862cd57f918f58fe2625c042718f4f1f84779752cf643e?d=identicon)[vladitot](/maintainers/vladitot)

---

Top Contributors

[![vladitot](https://avatars.githubusercontent.com/u/20747106?v=4)](https://github.com/vladitot "vladitot (17 commits)")[![essemok](https://avatars.githubusercontent.com/u/17266309?v=4)](https://github.com/essemok "essemok (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vladitot-phpnats2/health.svg)

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

###  Alternatives

[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[jeremykendall/query-auth

Signature generation and validation for REST API query authentication

142120.8k1](/packages/jeremykendall-query-auth)[bitrix24/b24phpsdk

An official PHP library for the Bitrix24 REST API

9230.2k4](/packages/bitrix24-b24phpsdk)[aphiria/aphiria

The Aphiria framework

1427.7k2](/packages/aphiria-aphiria)[sfcod/socketio

SocketIo adapter for Symfony

252.7k](/packages/sfcod-socketio)

PHPackages © 2026

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