MCP PHP SDK

SessionLockInterface

Serializes the requests of one session across the workers that serve it.

A request loads its session, changes it and writes it back whole, so two requests of one session running at the same time can overwrite each other's changes. The Protocol holds the lock from before it reads the session until it saved it, and releases it while a handler waits for the client. A stream polling for the client's answer only takes the lock when it is free.

Tags
author

Vitalii Cherepanov vbcherepanov@gmail.com

Table of Contents

Methods

acquire()  : void
Blocks until the lock of the session is held, or gives up after the implementation's timeout.
release()  : void
tryAcquire()  : bool
Takes the lock of the session only if no other request holds it right now, without waiting.

Methods

acquire()

Blocks until the lock of the session is held, or gives up after the implementation's timeout.

public acquire(Uuid $sessionId) : void
Parameters
$sessionId : Uuid
Tags
throws
SessionLockTimeoutException

when another request still held the lock after the timeout

SessionLockException

when the lock is already held by this instance, or the backend failed

tryAcquire()

Takes the lock of the session only if no other request holds it right now, without waiting.

public tryAcquire(Uuid $sessionId) : bool
Parameters
$sessionId : Uuid
Tags
throws
SessionLockException

when the lock is already held by this instance, or the backend failed

Return values
bool —

false when another request holds the lock

On this page

Search results