Version 2 is a rewrite of the PHP SDK. It keeps the same goal as v1, connecting your PHP application to SurrealDB, but changes most of the public surface. Queries are built with a fluent builder ($db->select($table)->where(...)->limit(10)), credentials are typed value objects, and the transport layer is built on PSR HTTP interfaces so you can swap in your own client.
Important
The SDK requires PHP 8.4 or later and works with SurrealDB server versions 1.0.0 up to (but not including) 4.0.0. The version is checked on connect unless you disable it.
If you are upgrading an existing project, start with the migration guide.
Getting started
Installation
Install the alpha release with Composer and add a PSR-18 HTTP client.
Quickstart
Connect to SurrealDB and run your first queries in a few minutes.
Core concepts
Connecting to SurrealDB
Open a connection over WebSocket or HTTP, select a namespace and database, and handle reconnection.
Authentication
Sign in and sign up with typed credentials, then manage tokens.
Executing queries
Run raw SurrealQL or use the fluent query builders for select, create, update, and delete.
Live queries
Subscribe to real-time changes over a WebSocket connection.
Advanced
Observability
Emit traces and metrics through OpenTelemetry or PSR-3 adapters.
Middleware
Intercept every RPC with built-in or custom middleware.
Events
Observe lifecycle and RPC traffic with PSR-14 events.
Sessions
Run multiple independent sessions over one connection.