Skip to content
Daniel Carbone edited this page Nov 6, 2026 · 1 revision

Event

$consul->Event wraps Consul's Event API for firing and listing custom user events.

use DCarbone\PHPConsulAPI\Event\UserEvent;

[$event, $wm, $err] = $consul->Event->Fire(event: new UserEvent(Name: 'deploy', Payload: 'v1.2.3'));
echo $event->ID;

[$events, $qm, $err] = $consul->Event->List(name: 'deploy');
foreach ($events as $e) {
    echo "{$e->Name}: {$e->Payload}\n"; // deploy: v1.2.3
}

Payload is the raw string. Consul returns it base64-encoded and the client decodes it for you. NodeFilter, ServiceFilter and TagFilter limit which agents receive the event.

Blocking on events

The event list endpoint uses a pseudo-index derived from event IDs. IDToIndex() converts an event ID to that index and returns a Brick\Math\BigInteger directly (not a response object):

use DCarbone\PHPConsulAPI\QueryOptions;

$lastIndex = $consul->Event->IDToIndex(uuid: end($events)->ID);
[$events, $qm, $err] = $consul->Event->List(name: 'deploy', opts: new QueryOptions(WaitIndex: $lastIndex));

See Big Integers for working with BigInteger.

See Responses and Errors and Query and Write Options.

Clone this wiki locally