PHPackages                             vluzrmos/jsonrpc - 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. vluzrmos/jsonrpc

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

vluzrmos/jsonrpc
================

JSON-RPC 2.0 Client and Server implementation for PHP 5.6+

v0.0.1(8mo ago)010MITPHPPHP &gt;=5.6

Since Aug 30Pushed 2mo agoCompare

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

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

JSON-RPC PHP 5.6 Library
========================

[](#json-rpc-php-56-library)

A simple and flexible PHP library to implement JSON-RPC 2.0 servers and clients. Supports PHP 5.6+, PSR-4 autoloading, and PHPUnit tests.

Features
--------

[](#features)

- JSON-RPC 2.0 protocol support
- Easy method registration and execution
- Error handling according to the spec
- Batch requests support
- Compatible with PHP 5.6 and above

Requirements
------------

[](#requirements)

- PHP &gt;= 5.6
- Composer

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

[](#installation)

```
composer require vluzrmos/jsonrpc
```

Usage Example
-------------

[](#usage-example)

### Registering Methods

[](#registering-methods)

```
use Vluzrmos\JsonRPC\Server;
use Vluzrmos\JsonRPC\Request;
use Vluzrmos\JsonRPC\Concerns\Method;

class SumMethod implements Method {
    public function getName() { return 'sum'; }
    public function execute(Request $request) {
        $params = $request->getParams();
        return array_sum($params);
    }
}

$server = new Server();
$server->addMethod(new SumMethod());
```

### Handling a JSON-RPC Request

[](#handling-a-json-rpc-request)

```
$json = '{"jsonrpc":"2.0","method":"sum","params":[1,2,3],"id":1}';
$response = $server->reply($json);

// $response is an instance of Response
print_r($response->toArray());
// Output:
// Array
// (
//     [jsonrpc] => 2.0
//     [result] => 6
//     [id] => 1
// )
```

### Batch Requests

[](#batch-requests)

```
$batch = '[
    {"jsonrpc":"2.0","method":"sum","params":[1,2],"id":1},
    {"jsonrpc":"2.0","method":"sum","params":[5,7],"id":2}
]';
$responses = $server->reply($batch);

foreach ($responses as $response) {
    print_r($response->toArray());
}
// Output:
// Array
// (
//     [jsonrpc] => 2.0
//     [result] => 3
//     [id] => 1
// )
// Array
// (
//     [jsonrpc] => 2.0
//     [result] => 12
//     [id] => 2
// )
```

### Notification (No Response)

[](#notification-no-response)

```
// Single notification (no 'id' field)
$json = '{"jsonrpc":"2.0","method":"sum","params":[1,2,3]}';
$response = $server->reply($json); // $response will be null
// Output:
// null
```

### Batch Notification

[](#batch-notification)

```
$batch = '[
    {"jsonrpc":"2.0","method":"sum","params":[1,2]},
    {"jsonrpc":"2.0","method":"sum","params":[5,7]}
]';
$responses = $server->reply($batch); // $responses will be an empty array or null
// Output:
// [] ou null
```

Usage with Request Objects
--------------------------

[](#usage-with-request-objects)

### Single Request Object

[](#single-request-object)

```
use Vluzrmos\JsonRPC\Request;

$request = new Request('sum', [10, 20, 30], 99);
$response = $server->reply($request);
print_r($response->toArray());
// Output:
// Array
// (
//     [jsonrpc] => 2.0
//     [result] => 60
//     [id] => 99
// )
```

### Request with Named Parameters

[](#request-with-named-parameters)

```
$request = new Request('sum', ['a' => 5, 'b' => 7], 'custom-id');
$response = $server->reply($request);
print_r($response->toArray());
// Output:
// Array
// (
//     [jsonrpc] => 2.0
//     [result] => 12
//     [id] => custom-id
// )
```

### Batch Requests with Request Objects

[](#batch-requests-with-request-objects)

```
$requests = [
    new Request('sum', [1, 2], 1),
    new Request('sum', [3, 4], 2)
];
$responses = $server->reply($requests);
foreach ($responses as $response) {
    print_r($response->toArray());
}
// Output:
// Array
// (
//     [jsonrpc] => 2.0
//     [result] => 3
//     [id] => 1
// )
// Array
// (
//     [jsonrpc] => 2.0
//     [result] => 7
//     [id] => 2
// )
```

Running Tests
-------------

[](#running-tests)

```
docker build -t jsonrpc-php56 .
docker run -it --rm jsonrpc-php56 php ./vendor/bin/phpunit
```

License
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance76

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity20

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

256d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/450848?v=4)[Vagner Luz do Carmo](/maintainers/vluzrmos)[@vluzrmos](https://github.com/vluzrmos)

---

Top Contributors

[![vluzrmos](https://avatars.githubusercontent.com/u/450848?v=4)](https://github.com/vluzrmos "vluzrmos (5 commits)")

---

Tags

httpclientcurlrpcserverjsonrpcjson-rpc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vluzrmos-jsonrpc/health.svg)

```
[![Health](https://phpackages.com/badges/vluzrmos-jsonrpc/health.svg)](https://phpackages.com/packages/vluzrmos-jsonrpc)
```

###  Alternatives

[datto/json-rpc-http

HTTP client and server for JSON-RPC 2.0

66525.9k5](/packages/datto-json-rpc-http)[graze/guzzle-jsonrpc

JSON-RPC 2.0 client for Guzzle

981.2M24](/packages/graze-guzzle-jsonrpc)[thiagof/laravelrpc

JsonRPC Client/Server services for Laravel 5

337.5k](/packages/thiagof-laravelrpc)

PHPackages © 2026

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