PHPackages                             rmh-media/php-nats-streaming - 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. rmh-media/php-nats-streaming

ActiveLibrary

rmh-media/php-nats-streaming
============================

PHP Client for nats-streaming-server.

0.3.0(6y ago)06.7k↓100%MITPHP

Since Nov 13Pushed 4y agoCompare

[ Source](https://github.com/rmh-media/php-nats-streaming)[ Packagist](https://packagist.org/packages/rmh-media/php-nats-streaming)[ RSS](/packages/rmh-media-php-nats-streaming/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (10)Used By (0)

PHP Nats Streaming Server Client
================================

[](#php-nats-streaming-server-client)

Intro
-----

[](#intro)

A php client for [Nats Streaming Server](https://nats.io/documentation/streaming/nats-streaming-intro/).

Uses [phpnats](https://github.com/repejota/phpnats) under the hood and closesly resembles it's api.

Requirements
------------

[](#requirements)

- php 5.6+
- [stan](https://github.com/nats-io/nats-streaming-server)

Installation
------------

[](#installation)

Get [composer](https://getcomposer.org/):

```
curl -O http://getcomposer.org/composer.phar && chmod +x composer.phar
```

Add php-nats-streaming as a dependency to your project

```
php composer.phar require 'rmh-media/php-nats-streaming:^0.3.0'
```

Usage
-----

[](#usage)

### Publish

[](#publish)

```
$options = new \NatsStreaming\ConnectionOptions();
$options->setClientID("test");
$options->setClusterID("test-cluster");
$c = new \NatsStreaming\Connection($options);

$c->connect();

// Publish
$r = $c->publish('special.subject', 'some serialized payload...');

// optionally wait for the ack
$gotAck = $r->wait();
if (!$gotAck) {
    ...
}

$c->close();
```

#### Note

[](#note)

If publishing many messages at a time, you might at first do this:

```
foreach ($req as $data){
    $r = $c->publish(...);
    $gotAck = $r->wait();
    if (!$gotAck) {
        ...
    }
}
```

It's actually *much* faster to do the following:

```
$rs = [];
foreach ($req as $data){
    $rs[] = $c->publish(...);
}

foreach ($rs as $r){
    $r->wait();
}
```

### Subscribe

[](#subscribe)

```
$options = new \NatsStreaming\ConnectionOptions();
$c = new \NatsStreaming\Connection($options);

$c->connect();

$subOptions = new \NatsStreaming\SubscriptionOptions();
$subOptions->setStartAt(\NatsStreamingProtos\StartPosition::First());

$sub = $c->subscribe('special.subject', function ($message) {
    // implement
}, $subOptions);

$sub->wait(1);

// not explicitly needed
$sub->unsubscribe(); // or $sub->close();

$c->close();
```

If you want to subscribe to multiple channels you can use `$c->wait()`:

```
...

$c->connect();

...

$sub = $c->subscribe('special.subject', function ($message) {
    // implement
}, $subOptions);
$sub2 = $c->subscribe('special.subject', function ($message) {
    // implement
}, $subOptions);

$c->wait();
```

### Queue Group Subscribe

[](#queue-group-subscribe)

```
$options = new \NatsStreaming\ConnectionOptions();
$c = new \NatsStreaming\Connection($options);

$c->connect();

$subOptions = new \NatsStreaming\SubscriptionOptions();
$sub = $c->queueSubscribe('specialer.subject', 'workgroup', function ($message) {
    // implement
}, $subOptions);

$sub->wait(1);

// not explicitly needed
$sub->close(); // or $sub->unsubscribe();

$c->close();
```

### Manual Ack

[](#manual-ack)

```
$options = new \NatsStreaming\ConnectionOptions();
$c = new \NatsStreaming\Connection($options);

$c->connect();

$subOptions = new \NatsStreaming\SubscriptionOptions();
$subOptions->setManualAck(true);

$sub = $c->subscribe('special.subject', function ($message) {
    $message->ack();
}, $subOptions);

$sub->wait(1);

$c->close();
```

License
-------

[](#license)

MIT, see [LICENSE](LICENSE)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.5% 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 ~78 days

Recently: every ~154 days

Total

9

Last Release

2473d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/258ae6b3352c99dc9e4b0bdce5bc11c039a7a92ffb9218b48aea56622919a90f?d=identicon)[andreas-rmh](/maintainers/andreas-rmh)

---

Top Contributors

[![byrnedo](https://avatars.githubusercontent.com/u/5528491?v=4)](https://github.com/byrnedo "byrnedo (23 commits)")[![andreas-rmh](https://avatars.githubusercontent.com/u/34645290?v=4)](https://github.com/andreas-rmh "andreas-rmh (3 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/rmh-media-php-nats-streaming/health.svg)

```
[![Health](https://phpackages.com/badges/rmh-media-php-nats-streaming/health.svg)](https://phpackages.com/packages/rmh-media-php-nats-streaming)
```

###  Alternatives

[byrnedo/php-nats-streaming

PHP Client for nats-streaming-server.

45313.1k](/packages/byrnedo-php-nats-streaming)[protobuf-php/protobuf-plugin

PHP Code generator plugin from Google's Protocol Buffers

57141.6k17](/packages/protobuf-php-protobuf-plugin)[ikilobyte/pulsar-client-php

PHP Native Client library for Apache Pulsar

61101.9k1](/packages/ikilobyte-pulsar-client-php)[agentsib/diadoc-php

Diadoc API implementation

111.5k1](/packages/agentsib-diadoc-php)

PHPackages © 2026

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