MCP PHP SDK

InMemoryNotificationBus implements NotificationBusInterface

FinalYes

A notification bus held in one process's memory.

Correct for stdio and for persistent runtimes where the whole server lives in one process (Swoole, FrankenPHP worker mode, ReactPHP). Under PHP-FPM it is not: the worker that publishes and the worker holding the stream open are different processes, and a notification published in one is invisible to the other. Psr16NotificationBus is the answer there.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Interfaces

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

Properties

$backlog  : int
$entries  : array<int, Notification>
$next  : 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.

Properties

Methods

__construct()

public __construct([int $backlog = 256 ]) : mixed
Parameters
$backlog : int = 256

how many notifications to keep before dropping the oldest

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}
On this page

Search results