Repository navigation
Session
Daniel Carbone edited this page Nov 6, 2026
·
1 revision
$consul->Session wraps Consul's Session API. Sessions are
mostly used to hold locks in the KV store.
use DCarbone\PHPConsulAPI\Consul;
use DCarbone\PHPConsulAPI\Session\SessionEntry;
[$sid, $wm, $err] = $consul->Session->Create(sessionEntry: new SessionEntry(
Name: 'my-lock',
TTL: '15s',
Behavior: Consul::SessionBehaviorRelease, // or Consul::SessionBehaviorDelete
));
// Renew before the TTL expires. Returns the renewed entries.
[$entries, $wm, $err] = $consul->Session->Renew(id: $sid);
[$wm, $err] = $consul->Session->Destroy(id: $sid);SessionEntry::$TTL is a string (e.g. '15s'), as Consul expects. LockDelay is a Time\Duration (see
Durations and Time). By default, Create attaches the node's serfHealth check. Use CreateNoChecks to create a
session with no health checks.
[$info, $qm, $err] = $consul->Session->Info(id: $sid); // SessionEntry[] (empty if not found)
echo $info[0]->Name . ' ' . $info[0]->TTL . ' ' . $info[0]->Behavior;
[$all, $qm, $err] = $consul->Session->List();
[$mine, $qm, $err] = $consul->Session->Node(node: 'my-node');