PHPackages                             php-websocket-rpc/rpc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. php-websocket-rpc/rpc

ActiveLibrary[HTTP &amp; Networking](/categories/http)

php-websocket-rpc/rpc
=====================

Shared data model, serialization, and middleware pipeline for RPC over WebSocket

v0.1.0(1mo ago)032MITPHPPHP &gt;=8.5

Since Jun 10Pushed 2mo agoCompare

[ Source](https://github.com/php-websocket-rpc/rpc)[ Packagist](https://packagist.org/packages/php-websocket-rpc/rpc)[ Docs](https://github.com/php-websocket-rpc/rpc)[ RSS](/packages/php-websocket-rpc-rpc/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (2)

php-websocket-rpc/rpc
=====================

[](#php-websocket-rpcrpc)

Shared data model, serialization, middleware pipeline, and contract system for RPC over WebSocket.

This is the foundation library — both `rpc-client` and `rpc-server` depend on it.

Install
-------

[](#install)

```
composer require php-websocket-rpc/rpc
```

Requires PHP 8.5+ and the `msgpack` extension.

Features
--------

[](#features)

- **Payload model** — base class and kind interfaces (request, response, notification, stream open/close/data)
- **Contract system** — `ContractInvocation`, `ContractResponse`, `ContractStreamInvocation`, `ContractStreamValue`, `ContractStreamClose`, `ContractPublish`
- **PHP Attributes** — `#[RpcSubscribe]`, `#[RpcStream]`, `#[RpcPublish]`, `#[NeedAuthorization]` for declaring RPC patterns on interfaces
- **Serialization** — `ContractSerializer` encodes/decodes values for wire transmission using `[FQCN, props]` format
- **Middleware pipeline** — `MiddlewarePipeline` for chaining request/response processors
- **Stream interfaces** — `StreamChannelAware`, `StreamSubscribable` for streaming and pub/sub
- **Authentication** — `AuthService` contract, `WebsocketUserInterface`, `User` value object, typed auth exceptions

Contract Attributes
-------------------

[](#contract-attributes)

AttributeTargetPurpose`#[RpcSubscribe]`MethodSubscribe to a named channel (receives push data)`#[RpcStream]`MethodStream data as an async iterable`#[RpcPublish]`MethodPublish data to a named channel`#[NeedAuthorization]`Method/ClassRequire authentication to access a method or entire interfaceAuthentication
--------------

[](#authentication)

### AuthService Contract

[](#authservice-contract)

A built-in contract that all clients can use to authenticate:

```
use PhpWebsocketRpc\Rpc\Contract\AuthService;

$auth = $client->createProxy(AuthService::class);
$user = $auth->authenticate('jwt-token-here');
// $user instanceof PhpWebsocketRpc\Rpc\Auth\User
// $user->id, $user->roles
```

### WebsocketUserInterface

[](#websocketuserinterface)

```
interface WebsocketUserInterface
{
    public function getUniqueIdentifier(): string;
    public function getRoles(): array;
}
```

### User (built-in value object)

[](#user-built-in-value-object)

```
$user = new User('user-42', ['admin', 'customer']);
echo $user->id;          // 'user-42'
echo $user->roles;       // ['admin', 'customer']
```

### Error Codes

[](#error-codes)

ExceptionCodeMeaning`AuthenticationException`-32010Invalid/expired/missing token`AuthorizationException`-32011Insufficient permissionsBoth extend `RpcDispatchException` and carry the error code in `getRpcCode()`.

Key Classes
-----------

[](#key-classes)

ClassPurpose`PhpWebsocketRpc\Rpc\Payload\Payload`Base class for all wire payloads`PhpWebsocketRpc\Rpc\Serialization\Serializer`Msgpack serialization`PhpWebsocketRpc\Rpc\Contract\ContractSerializer`Object encoding/decoding for contract data`PhpWebsocketRpc\Rpc\Contract\Attribute\RpcSubscribe`Mark a method as subscribe pattern`PhpWebsocketRpc\Rpc\Contract\Attribute\RpcStream`Mark a method as stream pattern`PhpWebsocketRpc\Rpc\Contract\Attribute\RpcPublish`Mark a method as publish pattern`PhpWebsocketRpc\Rpc\Contract\Attribute\NeedAuthorization`Mark a method/interface as requiring auth`PhpWebsocketRpc\Rpc\Contract\AuthService`Built-in authentication contract`PhpWebsocketRpc\Rpc\Auth\WebsocketUserInterface`Interface for authenticated user data`PhpWebsocketRpc\Rpc\Auth\User`Value object implementing WebsocketUserInterface`PhpWebsocketRpc\Rpc\Exception\AuthenticationException`Auth failure (-32010)`PhpWebsocketRpc\Rpc\Exception\AuthorizationException`Forbidden (-32011)`PhpWebsocketRpc\Rpc\Middleware\MiddlewarePipeline`Middleware chain

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance89

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

44d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/023a0bd17758df473ae6dad9f07575a8d0a8c36b06e83396b5962aecba38c722?d=identicon)[PrasWicaksono](/maintainers/PrasWicaksono)

---

Top Contributors

[![praswicaksono](https://avatars.githubusercontent.com/u/603125?v=4)](https://github.com/praswicaksono "praswicaksono (1 commits)")

---

Tags

asyncmiddlewarerpcwebsocketserializationamphpmsgpack

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/php-websocket-rpc-rpc/health.svg)

```
[![Health](https://phpackages.com/badges/php-websocket-rpc-rpc/health.svg)](https://phpackages.com/packages/php-websocket-rpc-rpc)
```

###  Alternatives

[hprose/hprose

It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.

2.0k221.3k37](/packages/hprose-hprose)[amphp/websocket-client

Async WebSocket client for PHP based on Amp.

1645.1M66](/packages/amphp-websocket-client)[amphp/http-server

A non-blocking HTTP application server for PHP based on Amp.

1.3k6.7M115](/packages/amphp-http-server)[amphp/websocket

Shared code for websocket servers and clients.

465.2M11](/packages/amphp-websocket)[hprose/hprose-swoole

Hprose asynchronous client &amp; standalone server based on swoole

17929.3k10](/packages/hprose-hprose-swoole)[hprose/hprose-yii

Hprose Server for Yii 2

357.2k](/packages/hprose-hprose-yii)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
