PHPackages                             operation-hardcode/php-rpc-server - 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. operation-hardcode/php-rpc-server

ActiveLibrary[API Development](/categories/api)

operation-hardcode/php-rpc-server
=================================

JSON RPC server implementation for PHP.

v0.1.0(4y ago)54MITPHPPHP ^8.1

Since Dec 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/operation-hardcode/php-rpc-server)[ Packagist](https://packagist.org/packages/operation-hardcode/php-rpc-server)[ RSS](/packages/operation-hardcode-php-rpc-server/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

[![test](https://github.com/operation-hardcode/php-rpc-server/workflows/ci/badge.svg?event=push)](https://github.com/operation-hardcode/php-rpc-server/workflows/ci/badge.svg?event=push)[![Codecov](https://camo.githubusercontent.com/fbeb95c01a2a3fa4f19d6eb5ba7f3c2c468c1b47ca716ae5556cdc561f12e3aa/68747470733a2f2f636f6465636f762e696f2f67682f6f7065726174696f6e2d68617264636f64652f7068702d7270632d7365727665722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/operation-hardcode/php-rpc-server)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/b5f69cbf4712d5252627d1c3842f9d7b3269348b8dd877be278b02a7ef9619eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f7065726174696f6e2d68617264636f64652f7068702d7270632d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/operation-hardcode/php-rpc-server)

JSON RPC Server implementation for PHP.
=======================================

[](#json-rpc-server-implementation-for-php)

The json-rpc is a very simple protocol. You can see this by reading the [protocol specification](https://www.jsonrpc.org/specification).

This library implements json-rpc server specification. It is easy to use and well typed.

### Contents

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Testing](#testing)
- [Stat Analysis](#stat-analysis)
- [License](#license)

Installation
------------

[](#installation)

```
composer require operation-hardcode/php-rpc-server
```

Usage
-----

[](#usage)

Since the json-rpc server has only one endpoint, you need a handler that knows how to determine from the name of the method the handler that you will handle the request. You can write it yourself, if the `OperationHardcode\PhpRpcServer\RpcHandler` interface is implemented. Or use the ready-made one that comes with the library, the `OperationHardcode\PhpRpcServer\InvokableRpcHandler`.

To start to use the rpc server, instantiate the `RpcServer`:

```
use OperationHardcode\PhpRpcServer\RpcServer;
use OperationHardcode\PhpRpcServer\RpcRequest;
use OperationHardcode\PhpRpcServer\RpcResponse;
use OperationHardcode\PhpRpcServer\Protocol\Validation\ValidateRequest;

$server = RpcServer::new([
    'users.get' => function (RpcRequest $request, ?RpcResponse $response = null): ?RpcResponse {
        return $response?->addResult([10, 11]);
    }
])

$server->process('{"jsonrpc": "2.0", "method": "users.get", "id": 1}');
```

The rpc-server does not fetch the json, it just processes it according to the specification. This gives you the freedom to use the server, because you can pass the json fetched any way you know: via http, web sockets or even via tcp.

As you may have noticed, handlers may not have an RpcResponse object. If so, it is a notification, not a request, so no response to the client will follow. You can simply return this object (because it is null) or null directly.

The rpc-server uses validators to validate json against the specification. If you want to add your own validators, you must implement the `OperationHardcode\PhpRpcServer\Protocol\Validation\ValidateRequest` interface. In the `validate` method you will get the raw payload to ensure it satisfy your extended protocol rules.

```
use OperationHardcode\PhpRpcServer\RpcServer;
use OperationHardcode\PhpRpcServer\RpcRequest;
use OperationHardcode\PhpRpcServer\RpcResponse;
use OperationHardcode\PhpRpcServer\Protocol\Validation\ValidateRequest;
use Psr\Log\NullLogger;

final class CustomValidator implements ValidateRequest
{
    /** {@inheritdoc} */
    public function validate(array $payload): bool
    {
        return false;
    }
}

$server = RpcServer::new([
    'users.get' => function (RpcRequest $request, ?RpcResponse $response = null): ?RpcResponse {
        return $response?->addResult([10, 11]);
    }
], new NullLogger(), [new CustomValidator()])

$server->process('{"jsonrpc": "2.0", "method": "users.get", "id": 1}');
```

If your validator fails, the error `INVALID_REQUEST` will be returned to the client.

If you are not satisfied with the standard request handler, you can write your own.

```
use OperationHardcode\PhpRpcServer\RpcHandler;
use OperationHardcode\PhpRpcServer\RpcRequest;
use OperationHardcode\PhpRpcServer\RpcResponse;
use OperationHardcode\PhpRpcServer\RpcServer;

final class YourOwnRpcHandler implements RpcHandler
{
    public function handle(RpcRequest $request, ?RpcResponse $response = null) : ?RpcResponse
    {
        //
    }
}

$server = new RpcServer(new YourOwnRpcHandler());

$server->process('{"jsonrpc": "2.0", "method": "users.get", "id": 1}');
```

Examples
--------

[](#examples)

More extensive code examples reside in the [`examples`](examples) directory.

Testing
-------

[](#testing)

```
$ composer test
```

Stat Analysis
-------------

[](#stat-analysis)

```
$ composer lint
```

License
-------

[](#license)

The MIT License (MIT). See [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

1610d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b0c87976a285325177559e27d154a9b5019466800c6a3342db916140c512ede?d=identicon)[kafkiansky](/maintainers/kafkiansky)

---

Top Contributors

[![kafkiansky](https://avatars.githubusercontent.com/u/37590388?v=4)](https://github.com/kafkiansky "kafkiansky (10 commits)")

---

Tags

phprpcjson-rpc

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/operation-hardcode-php-rpc-server/health.svg)

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

###  Alternatives

[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[jsonrpc/jsonrpc

JSON-RPC 2.0 client/server implementation

53407.1k4](/packages/jsonrpc-jsonrpc)[hyperf/jet

Jet is a unification model RPC Client, built-in JSON RPC protocol, available to running in ALL PHP environments, including PHP-FPM and Swoole/Hyperf environments.

6119.1k](/packages/hyperf-jet)[comgate/sdk

Comgate PHP SDK

13327.8k](/packages/comgate-sdk)[ufo-tech/rpc-exceptions

Exception package RPC server error codes

164.2k4](/packages/ufo-tech-rpc-exceptions)

PHPackages © 2026

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