Download the PHP package utopia-php/nats without Composer
On this page you can find all versions of the php package utopia-php/nats. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nats
nats.php
[!IMPORTANT] This repository is a read-only mirror of the utopia-php monorepo. Development happens in
packages/nats— please open issues and pull requests there.
A modern PHP client for NATS messaging system with JetStream and Key-Value store support.
Requirements
- PHP 8.1+
ext-jsonext-sodium(optional, for NKey/JWT authentication)
Installation
Quick start
Core NATS
Connecting
Publishing
Subscribing
Request-reply
Connection management
JetStream
Streams
Publishing with acknowledgment
Publishing a batch
publish() waits for each acknowledgment before it sends the next message, so a
batch of N messages costs N round trips. publishMany() writes a window of
messages first and reads their acknowledgments afterwards, which costs one round
trip per window. Each message keeps its own acknowledgment, so deduplication and
per-message errors work the same way.
The window argument sets how many messages stay in flight before their
acknowledgments are collected. A message the server rejects throws, as it does on
publish().
Consumers
Key-value store
Authentication
TLS
Event callbacks
Testing
Batched requests
Connection::requestBatch() sends independent requests together and delivers each outcome to reply as it arrives. The callback receives the original input index and either a Message or a Throwable. One missing reply does not delay successful replies or discard their outcomes.
Request has read-only typed fields; both request() and requestBatch() use its subject validation and the same request lifecycle. The method returns void; collect results in the callback if you need an array. Completion order can differ from input order. The timeout is one response deadline for the whole group, starting after the write, rather than a separate wait per reply. Callback execution counts toward that deadline. Empty input performs no I/O. Invalid input throws before any request is published; request headers and payload limits follow request().
If the callback throws, collection stops immediately, pending state is cleaned up, and the exception propagates. Requests already sent are not cancelled or replayed. Later replies can still arrive. Use one owner for reading the connection; nested reads from the callback throw LogicException.
This differs from requestMany(), which sends one request and gathers several responses. Ambiguous writes are not replayed on reconnect. Use JetStream::ackBatch() to confirm a selected list of JetStreamMessage instances. JetStream constructs each acknowledgement; its callback receives the original index and null on server confirmation or a Throwable on failure. The consumer's configured acknowledgement policy still applies. Use AckPolicy::Explicit to leave messages outside the list unacknowledged. With AckPolicy::All, acknowledging a later message also acknowledges earlier messages, including those outside the list.
Single request() calls retain one retry for an explicit stale-connection rejection. Batch requests do not retry. Neither path replays an ambiguous write.
License
Apache-2.0
All versions of nats with dependencies
ext-json Version *