Version 2 of the PHP SDK exposes two ways to observe what it is doing. The high-level subscribe() method covers connection lifecycle changes with a simple callback. The lower-level PSR-14 event dispatcher emits a richer stream that includes per-request events, and integrates with framework dispatchers.
Lifecycle events with subscribe()
Use subscribe() for quick hooks into the connection lifecycle. Pass an event name and a listener; the method returns a closure that removes the listener when called.
The available event names are connecting, connected, reconnecting, disconnected, error, auth, and using. This is the simplest option when you only need to react to the connection coming up, dropping, or re-authenticating. See Connecting to SurrealDB and Authentication for lifecycle examples.
PSR-14 events
For full observation, including every RPC request and response, the SDK dispatches typed event objects through a PSR-14 event dispatcher. Unlike subscribe(), this stream reaches RPC-level events and lets you reuse a framework's dispatcher.
By default the SDK creates its own dispatcher. To receive events, either register listeners on a dispatcher you control and pass it through DriverOptions, or pass your framework's PSR-14 dispatcher.
The bundled ListenerProvider matches a listener against the event class and any of its parents or interfaces, so you can listen to a single event type or a shared base.
Using a framework dispatcher
Because the SDK depends only on the PSR-14 EventDispatcherInterface, you can pass the dispatcher from Laravel, Symfony, or any PSR-14 bridge. The SDK then dispatches its events into your application's existing listener setup.
Event catalogue
All events live in the SurrealDB\SDK\Events namespace and are readonly value objects.
| Event | Dispatched when | Payload |
|---|---|---|
Connecting | A connection attempt starts | none |
Connected | The connection is established and ready | version |
Disconnected | The connection closes | none |
Reconnecting | A dropped connection is being re-established | none |
ConnectionError | A connection-level error occurs | error |
AuthChanged | A session's authentication changes or clears | tokens, session |
NamespaceDatabaseSelected | The namespace or database changes | the selection, session |
RpcRequestSent | Just before a request is handed to the transport | request |
RpcResponseReceived | After a response is received (success or error) | request, response |
LiveMessageReceived | A live query notification arrives | message |
Note
Choosing between them
Use
subscribe()for connection lifecycle hooks with the least setup.Use the PSR-14 dispatcher when you need per-request events, want to fan events into a framework's listeners, or are building observability tooling.
Learn more
Surreal API reference for the
subscribe()signatureObservability for tracing and metrics
Connecting to SurrealDB for the lifecycle these events track