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. [API Development](/categories/api)
4. /
5. php-websocket-rpc/rpc

ActiveLibrary[API Development](/categories/api)

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

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

03PHP

Since May 21Pushed 2w agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

21

—

LowBetter than 18% of packages

Maintenance63

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### 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)")

### 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

[facebook/php-business-sdk

PHP SDK for Facebook Business

90923.5M35](/packages/facebook-php-business-sdk)[exsyst/swagger

A php library to manipulate Swagger specifications

35916.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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