Download the PHP package php-websocket-rpc/rpc-server without Composer
On this page you can find all versions of the php package php-websocket-rpc/rpc-server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-websocket-rpc/rpc-server
More information about php-websocket-rpc/rpc-server
Files in php-websocket-rpc/rpc-server
Package rpc-server
Short Description Async RPC server over WebSocket using amphp and msgpack
License MIT
Homepage https://github.com/php-websocket-rpc/rpc-server
Informations about the package rpc-server
php-websocket-rpc/rpc-server
Async RPC server over WebSocket using amphp and msgpack.
Install
Requires PHP 8.5+, ext-msgpack, and the amphp ecosystem.
Quick Start
The client then uses createProxy():
Features
- Contract services — register interface implementations, auto-dispatched via
ContractRegistry - Streaming — methods returning
Iteratorare automatically streamed to the client - Subscribe/Publish —
#[RpcSubscribe]and#[RpcPublish]attributes on interface methods - Authentication —
useAuthentication()with pluggable providers,#[NeedAuthorization]attribute - Middleware — pipeline for rate limiting, logging, auth, etc.
- Client sessions — track connected clients with per-session attributes
Authentication & Authorization
You must implement AuthenticationProvider to validate tokens and AuthorizationProvider to authorize method calls.
The framework provides built-in implementations for testing.
The AuthService is automatically registered and can be used to authenticate clients.
The ClientSessionContext is a fiber-safe accessor for session attributes.
Quick Setup
Protecting Methods
Use the #[NeedAuthorization] attribute on your contract interface:
Client Flow
Custom Authentication Provider
Implement AuthenticationProvider to use JWT, database, or any other logic:
Custom Authorization Provider
For fine-grained authorization (resource ownership, IP checks, etc.):
Statelessness
The AuthenticationProvider::validateToken() method must be stateless for cross-replica deployments. Use JWT (self-contained) or look up from a shared store (Redis/DB). It returns a Token value object (id, issuer, subject, audience, expiry) — the actual user data is resolved separately via UserProvider::getUser(). The framework only stores the authenticated user per-WebSocket-connection in memory, which is freed on disconnect.
Contract Services
Define an interface with attributes:
Register the implementation:
Architecture
The server uses a builder + adapter pattern to keep the core framework-agnostic:
RpcServerBuildercollects all configuration (services, middleware, auth) and callsbuild()to produce a configuredRpcServerRpcServeris the runtime: dispatches messages, manages sessions, and streams — it has zero amphp imports in its coreAmpWebSocketServerAdapterbridges amphp's HTTP/WebSocket layer toRpcServer, creatingClientSessionon upgrade and wrapping the amp client inClient(fromPhpWebsocketRpc\Rpc\Transport\Amp)- Transport interfaces (
WebSocketClientInterface,MessageInterface,TlsInfoInterface) inPhpWebsocketRpc\Rpc\Transportdefine the boundary; amp implementations live in a sub-namespace
Key Classes
| Class | Purpose |
|---|---|
PhpWebsocketRpc\RpcServer\Server\RpcServerBuilder |
Fluent builder — configure services, middleware, auth, then build() |
PhpWebsocketRpc\RpcServer\Server\RpcServer |
Runtime core — dispatches messages, manages sessions, no amphp deps |
PhpWebsocketRpc\RpcServer\Adapter\AmpWebSocketServerAdapter |
Bridges amphp HTTP/WebSocket to RpcServer |
PhpWebsocketRpc\RpcServer\Server\RpcDispatcher |
Composes middleware pipeline with router dispatch |
PhpWebsocketRpc\RpcServer\Server\ContractRegistry |
Manages contract service implementations |
PhpWebsocketRpc\RpcServer\Server\ClientSession |
Represents a connected client |
PhpWebsocketRpc\RpcServer\Stream\StreamChannel |
Manages a named stream channel |
PhpWebsocketRpc\RpcServer\Middleware\RateLimiterMiddleware |
Rate limiting middleware |
PhpWebsocketRpc\RpcServer\Auth\AuthenticationProvider |
Interface for token validation (returns Token) |
PhpWebsocketRpc\RpcServer\Auth\UserProvider |
Interface for resolving user details from a token subject |
PhpWebsocketRpc\RpcServer\Auth\AuthorizationProvider |
Interface for fine-grained authorization |
PhpWebsocketRpc\RpcServer\Auth\StaticTokenAuthenticationProvider |
Simple static-token auth provider |
PhpWebsocketRpc\RpcServer\Auth\InMemoryUserProvider |
Simple in-memory user provider for testing |
PhpWebsocketRpc\RpcServer\Auth\AuthService |
Built-in auth handler (auto-registered) |
PhpWebsocketRpc\RpcServer\Auth\ClientSessionContext |
Fiber-safe session accessor |
PhpWebsocketRpc\Rpc\Transport\Amp\Client |
Wraps amphp's WebsocketClient for RpcServer |
PhpWebsocketRpc\Rpc\Transport\FramedConnection |
Serializes/deserializes Payload over binary WebSocket |
All versions of rpc-server with dependencies
ext-msgpack Version *
amphp/amp Version ^3
amphp/websocket-server Version ^4
amphp/http-server Version ^3
amphp/http-server-router Version ^2
psr/log Version ^3
php-websocket-rpc/rpc Version ^0.1