PHPackages                             php-websocket-rpc/rpc-client - 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-client

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

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

Async RPC client over WebSocket using amphp and msgpack

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

Since Jun 10Pushed 2mo agoCompare

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

READMEChangelogDependencies (5)Versions (2)Used By (0)

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

[](#php-websocket-rpcrpc-client)

Async RPC client over WebSocket using amphp and msgpack.

Install
-------

[](#install)

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

Requires PHP 8.5+, `ext-msgpack`, and the amphp ecosystem.

Quick Start
-----------

[](#quick-start)

```
use PhpWebsocketRpc\RpcClient\Client\RpcClient;

$client = RpcClient::connect('ws://127.0.0.1:9502/rpc');

// ─── Using contract proxies ───

$math = $client->createProxy(MathService::class);

$result = $math->add(10, 5);               // call/response
echo $result;                               // 15

$math->log('Hello!');                       // notification

foreach ($math->count(10) as $value) {      // streaming
    echo $value;
}

$math->onEvent(function (string $event) {   // subscribe
    echo "Got: $event";
});

$chat->send('Hello!');                      // publish
```

Authentication
--------------

[](#authentication)

### Authenticating

[](#authenticating)

Use the built-in `AuthService` contract to authenticate:

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

$auth = $client->createProxy(AuthService::class);
$user = $auth->authenticate('your-token-here');

// $user is a User object (implements WebsocketUserInterface)
echo $user->id;      // user identifier
echo $user->roles;   // ['customer', 'admin']
```

### Handling Auth Errors

[](#handling-auth-errors)

```
use PhpWebsocketRpc\Rpc\Exception\AuthenticationException;
use PhpWebsocketRpc\Rpc\Exception\AuthorizationException;

try {
    $user = $auth->authenticate('invalid-token');
} catch (AuthenticationException $e) {
    echo $e->getRpcCode();      // -32010
    echo $e->getMessage();      // 'Invalid or expired token'
}

try {
    $chat->deleteMessage('msg-1');  // requires admin role
} catch (AuthorizationException $e) {
    echo $e->getRpcCode();      // -32011
    echo $e->getMessage();      // 'Requires one of roles: admin...'
}

// Generic catch for all RPC errors
use PhpWebsocketRpc\Rpc\Exception\RpcDispatchException;

try {
    $result = $math->add(10, 5);
} catch (RpcDispatchException $e) {
    echo $e->getRpcCode();      // e.g. -32601 (METHOD_NOT_FOUND)
}
```

### Logout

[](#logout)

```
$auth->logout();  // clears auth state for this connection
```

Features
--------

[](#features)

- **Contract proxies** — `createProxy()` generates a dynamic proxy from any interface using `proxy-manager-lts`
- **5 patterns** — call/response, notification, streaming, subscribe, publish
- **Authentication** — built-in `AuthService` contract with typed exceptions
- **Fire-and-forget** — notifications with no response
- **Stream subscriptions** — async iterables for streaming data (supports `foreach`)
- **Publish/Subscribe** — named channels with `#[RpcSubscribe]` / `#[RpcPublish]`
- **Middleware** — client-side middleware pipeline

Contract Proxies
----------------

[](#contract-proxies)

Define a shared interface:

```
interface MathService
{
    public function add(int $a, int $b): int;
    public function mul(int $a, int $b): int;
}
```

Use it transparently:

```
$math = $client->createProxy(MathService::class);
$sum = $math->add(10, 5);        // returns 15 — no boilerplate
```

The proxy is generated by `friendsofphp/proxy-manager-lts` using `NullObjectFactory` + `AccessInterceptorValueHolderFactory` — no `eval()` or runtime code generation.

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

[](#key-classes)

ClassPurpose`PhpWebsocketRpc\RpcClient\Client\RpcClient`Main client — connect, create proxies, close`PhpWebsocketRpc\RpcClient\Client\ContractProxyFactory`Generates dynamic proxies from interfaces`PhpWebsocketRpc\RpcClient\Client\PendingRequestStore`Tracks in-flight requests`PhpWebsocketRpc\RpcClient\Client\SubscriptionManager`Manages active stream subscriptions`PhpWebsocketRpc\Rpc\Transport\FramedConnection`Low-level framed WebSocket connection`PhpWebsocketRpc\Rpc\Contract\AuthService`Built-in auth contract`PhpWebsocketRpc\Rpc\Auth\User`Authenticated user value object`PhpWebsocketRpc\Rpc\Exception\AuthenticationException`Auth failure (-32010)`PhpWebsocketRpc\Rpc\Exception\AuthorizationException`Forbidden (-32011)

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance89

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

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

asyncclientproxyrpcwebsocketamphpmsgpack

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[amphp/http-server

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

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

Async WebSocket client for PHP based on Amp.

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

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.

7299.5M207](/packages/amphp-http-client)[swow/swow

Coroutine-based multi-platform support engine with a focus on concurrent I/O

1.3k2.2M89](/packages/swow-swow)[ratchet/pawl

Asynchronous WebSocket client

61710.0M246](/packages/ratchet-pawl)[amphp/websocket

Shared code for websocket servers and clients.

465.2M11](/packages/amphp-websocket)

PHPackages © 2026

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