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

ActiveNeos-package[HTTP &amp; Networking](/categories/http)

flownative/nats
===============

A NATS client for PHP.

7191PHP

Since Apr 2Pushed 7y ago3 watchersCompare

[ Source](https://github.com/flownative/nats)[ Packagist](https://packagist.org/packages/flownative/nats)[ RSS](/packages/flownative-nats/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![MIT license](https://camo.githubusercontent.com/4661abfe916186acde514558e7f040833cb63ba7098401a51ce339cbb2b4cf9e/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](http://opensource.org/licenses/MIT)[![Packagist](https://camo.githubusercontent.com/d691a04e7aa048ea4ec33d27abd46b69345a51f3978e36735e29efd3a1cb967f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c6f776e61746976652f6e6174732e737667)](https://packagist.org/packages/flownative/nats)

NATS PHP Client
===============

[](#nats-php-client)

A PHP implementation of a client for [NATS](https://nats.io/).

🚧 Please note that this package is currently under development and not ready for general use yet.

Usage
-----

[](#usage)

Install the package using composer:

```
composer require flownative/nats

```

In PHP, open a new connection with

```
use Flownative\Nats\Connection;

// Connect to a server
$nats = new Connection(
    'nats://localhost:4222',
    [
        'username' => 'nats',
        'password' => 'password',
        'debug' => true
    ]
);

// Simple publisher
$nats->publish('foo', 'Hello World');

// Simple asynchronous subscriber
$nats->subscribe('foo', function($message) {
    printf("\nReceived a message: %s\n", $message->getBody());
});
```

This will open a new socket connection and send a CONNECT and PING to the given NATS server an do a simple PUB / SUB run:

```
 🚀  Connecting with server via nats://localhost:4222 ...
>>>> CONNECT {"lang":"php","version":"dev-master@7dd6908c3e9f26e1094873a510547cd950bcb2c7","verbose":false,"pedantic":false,"user":"nats","pass":"password"}
> PING
> SUB foo vjxX30gfutwGDBxfLuKR
>>>> PUB foo 11
Hello World
getBody()));
});

// Send a request which will be answered by the "hello" subscriber:
$nats->request(
    'hello',
    'Robert',
    function (Message $message) {
        printf("Request returned: %s\n", $message->getBody());
    }
);
```

Development
-----------

[](#development)

### Tests

[](#tests)

Unit tests can be executed with PhpUnit. A configuration file is included in the main directory. Unit tests are self-contained and don't need an actual NATS server running.

### Protocol Buffer schema for NATS Streaming

[](#protocol-buffer-schema-for-nats-streaming)

Since NATS Streaming uses Google's Protocol Buffers for its messages, we need corresponding PHP classes according to the given schema. This is defined by means of a .proto file, which retrieved from the [Go Nats Streaming project on Github](https://github.com/nats-io/go-nats-streaming/blob/master/pb/protocol.proto). Based on this file, you can automatically create corresponding PHP code using the Protocol Buffers Compiler.

[https://developers.google.com/protocol-buffers/docs/downloads](Download) and install the compiler (called "protoc")

Credits
-------

[](#credits)

This package was developed by Robert Lemke as part of his work at [Flownative](https://www.flownative.com). It was written from scratch, but significantly inspired by [the work by Raül Pérez](https://github.com/repejota/phpnats).

License
-------

[](#license)

This package is licensed under the MIT license.

Contributions
-------------

[](#contributions)

Pull-Requests are welcome. Make sure to read the [Code Of Conduct](CodeOfConduct.rst).

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

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/10280881?v=4)[Flownative](/maintainers/flownative)[@flownative](https://github.com/flownative)

---

Top Contributors

[![robertlemke](https://avatars.githubusercontent.com/u/95582?v=4)](https://github.com/robertlemke "robertlemke (8 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/flownative-nats/health.svg)](https://phpackages.com/packages/flownative-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)
