Session: How to Get the Current Session Node

When working in a RavenDB cluster, a database can reside on multiple nodes.
When the client needs to send a request to the server, it can have several nodes to choose from.

The client uses this logic to determine which node to send the request to.
Learn more about load balancing the client requests in this overview.

Use the getCurrentSessionNode method from the advanced session operations to find out what is the current node that the session sends its requests to.

Syntax

public function getCurrentSessionNode(): ServerNode;

Return Value

The return value of getCurrentSessionNode is a ServerNode object

class ServerNode
{
    private ?Url $url = null;
    private ?string $database = null;
    private string $clusterTag;
    private ?ServerNodeRole $serverRole = null;

    public function __construct()
    {
        $this->serverRole = ServerNodeRole::none();
    }

    // ... getters and setters
}

class ServerNodeRole
{
    public static function none(): ServerNodeRole;
    public static function promotable(): ServerNodeRole;
    public static function member(): ServerNodeRole;
    public static function rehab(): ServerNodeRole;
}

Example

$serverNode = $session->advanced()->getCurrentSessionNode();
echo $serverNode->getUrl();