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

ActiveLibrary

yueguan/phpnats2
================

v1.0.0(7y ago)017PHP

Since Mar 12Pushed 7y agoCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

phpnats-copy
============

[](#phpnats-copy)

**Travi**

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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2620d ago

### Community

Maintainers

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

---

Top Contributors

[![yueguan666](https://avatars.githubusercontent.com/u/48473959?v=4)](https://github.com/yueguan666 "yueguan666 (6 commits)")

### Embed Badge

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

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

PHPackages © 2026

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