InMemoryNotificationBus implements NotificationBusInterface
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
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
$backlog read-only
private
int
$backlog
= 256
$entries
private
array<int, Notification>
$entries
= []
$next
private
int
$next
= 0
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
intpublish()
Publishes a notification to every stream currently reading forward.
public
publish(Notification $notification) : void
Parameters
- $notification : Notification
since()
Notifications published after $cursor, and the cursor to read from next.
public
since(int $cursor) : Notification>, int}
Parameters
- $cursor : int