MCP PHP SDK

Psr6NotificationBus implements NotificationBusInterface

FinalYes

A notification bus over any PSR-6 cache pool, so publishers and listen streams in different processes can see each other.

It works like Psr16NotificationBus, with the same keys and the same trade-off: two publishers can take the same sequence number, and one of their entries is then lost.

Tags
author

Nicolas Grekas p@tchwork.com

Table of Contents

Interfaces

NotificationBusInterface
Carries server-initiated notifications to whichever `subscriptions/listen` streams are open.

Constants

CURSOR_KEY  : mixed = 'cursor'

Properties

$backlog  : int
$cache  : CacheItemPoolInterface
$logger  : LoggerInterface
$messageFactory  : MessageFactory
$prefix  : string
$ttl  : int

Methods

__construct()  : mixed
cursor()  : int
The cursor a stream opening now should start from.
publish()  : void
Publishes a notification to every stream currently reading forward.
since()  : Notification>, int}
Notifications published after $cursor, and the cursor to read from next.
key()  : string

Constants

Properties

Methods

__construct()

public __construct(CacheItemPoolInterface $cache[, string $prefix = 'mcp.notifications.' ][, int $ttl = 120 ][, int $backlog = 256 ][, LoggerInterface $logger = new NullLogger() ][, MessageFactory|null $messageFactory = null ]) : mixed
Parameters
$cache : CacheItemPoolInterface
$prefix : string = 'mcp.notifications.'

namespace for this bus's keys, so one pool can carry several

$ttl : int = 120

how long an entry stays readable, in seconds

$backlog : int = 256

how many entries a reader will look back over

$logger : LoggerInterface = new NullLogger()
$messageFactory : MessageFactory|null = null

cursor()

The cursor a stream opening now should start from.

public cursor() : int

Deliberately "now" and not "the beginning": a client that subscribes wants what happens next, not a replay of everything the server has done.

Return values
int

since()

Notifications published after $cursor, and the cursor to read from next.

public since(int $cursor) : Notification>, int}
Parameters
$cursor : int
Return values
Notification>, int}

key()

private key(string $suffix) : string
Parameters
$suffix : string
Return values
string
On this page

Search results