PHPackages                             acgrid/json-rpc-php - 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. acgrid/json-rpc-php

ActiveLibrary

acgrid/json-rpc-php
===================

Port of Pozo/json-rpc-php library into PHP 5/7

v1.0.2(5y ago)1701GPL-3.0PHPPHP &gt;=5.5

Since Mar 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/acgrid/json-rpc-php)[ Packagist](https://packagist.org/packages/acgrid/json-rpc-php)[ Docs](https://github.com/acgrid/json-rpc-php)[ RSS](/packages/acgrid-json-rpc-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (5)Used By (0)

[JSON-RPC 2.0](http://www.jsonrpc.org/spec.html) Client/Server library for PHP with Composer PSR-4 enabled

### LICENSE

[](#license)

The original author `pozo` did not state any license used. Please inform me if you do not allow forking and porting.

\###Requirements PHP 5.5.0+, with composer PSR-4 support.

Install with `composer require acgrid/json-rpc-php` or add `"acgrid/json-rpc-php": "@dev"` to your `composer.json`.

\###Used predefined classes and interfaces

- [ReflectionClass](http://www.php.net/manual/en/class.reflectionclass.php)
- [ReflectionMethod](http://www.php.net/manual/en/class.reflectionmethod.php)
- [SPL Exceptions](http://php.net/manual/en/spl.exceptions.php)

NOTE
====

[](#note)

The following README is written by original author. Please keep in mind that namespace is introduced already.

\#How do I use the client? After you instantiate the `JsonRpcClient` with the server URL, there have two option to send a request. Both method using the `RpcRequest` class @ `lib/client/` which help us to sending a well formatted request. Step by step tuturial soon. ##Single request ###Sending a request So, triggering a single request after `$client = new JsonRpcClient('http://serverurl');` you can use one of the following methods:

\####\_\_call() magic method(recommended) Parameters sequence must represent the same as server implementation and notification not allowed

```
$response = $client->add($a,$b);

```

Is equal with

```
$response = $client->{'add'}($a,$b);

```

\####RpcRequest

1. Sorted parameters

RIGHT

```
$response = $client->call(new RpcRequest('sanitize',array(array(1,2,3))));
$response = $client->call(new RpcRequest('deleteById',array(3)));

```

WRONG

```
$response = $client->call(new RpcRequest('sanitize',array(1,2,3)));
$response = $client->call(new RpcRequest('deleteById',3));

```

2. Named parameters Sequence is not necessary, the server will sorting params if these exits **case sensitive**

    $response = $client-&gt;call(new RpcRequest('add',array('bValue'=&gt;$b,'aValue'=&gt;$a)));
3. Notification

    $response = $client-&gt;call(new RpcRequest('deleteAndUpdtae',array(2),true)); $response = $client-&gt;call(new RpcRequest('update',null,true));

\###Working with the response *Please note that the client side deliberately less implemented, so you can freely manage the response, for example, wrapping the reponse object in `JsonRpcClient` and when you got an unexpected answer, throw an exception etc.*

If the request is not a notification, and the process was successful, the `$response` will be an object which contain `id`,`jsonrpc` and `result` fields, otherwise the result object will contain `error` instead of `result`. The `error` object has three members, `message`,`code` and `data` which is optional. So in `$response = $client->add($a,$b);` case `var_dump($response)` will look like this if `$a` 10 `$b` 20 :

```
object(stdClass)#19 (3) {
  ["jsonrpc"]=>
  string(3) "2.0"
  ["result"]=>
  int(30)
  ["id"]=>
  int(1)
}

```

And if we call accidentally `addd` instead of `add` :

```
object(stdClass)#19 (3) {
  ["jsonrpc"]=>
  string(3) "2.0"
  ["error"]=>
  object(stdClass)#20 (2) {
    ["code"]=>
    int(-32601)
    ["message"]=>
    string(16) "Method not found"
  }
  ["id"]=>
  int(1)
}

```

\##Batch request ###Sending a request You can send more than one request at the same time. In this case you must use an array util to collect RpcRequest objects and passing into `callBatch` method

1. No one

    $client = new JsonRpcClient("");

    $listOfCalls = array();

    array\_push($listOfCalls,new RpcRequest("add",array(33,77))); array\_push($listOfCalls,new RpcRequest("divide",array(44,11),true)); array\_push($listOfCalls,new RpcRequest("subtract",array(2,12.3))); array\_push($listOfCalls,new RpcRequest("invalidateSession"));

    $responseArray = $client-&gt;callBatch($listOfCalls);
2. One of them is a notification

    $client = new JsonRpcClient(""); $listOfCalls = array();

    array\_push($listOfCalls,new RpcRequest("add",array(33,77))); array\_push($listOfCalls,new RpcRequest("add",array(44,11),true)); array\_push($listOfCalls,new RpcRequest("add",array(2,12.3)));

    $responseArray = $client-&gt;callBatch($listOfCalls);
3. All request is notification

    $client = new JsonRpcClient(""); $listOfCalls = array();

    array\_push($listOfCalls,new RpcRequest("add",array(33,77),true)); array\_push($listOfCalls,new RpcRequest("add",array(44,11),true)); array\_push($listOfCalls,new RpcRequest("add",array(2,12.3),true));

    $responseArray = $client-&gt;callBatch($listOfCalls);

\###Accepting the response Only difference between the Single request that the callBatch will return an array of response objects so `$responseArray` look like this in case of 1)

```
array(3) {
  [0]=>
  object(stdClass)#8 (3) {
    ["jsonrpc"]=>
    string(3) "2.0"
    ["result"]=>
    int(110)
    ["id"]=>
    int(2)
  }
  [1]=>
  object(stdClass)#12 (3) {
    ["jsonrpc"]=>
    string(3) "2.0"
    ["result"]=>
    int(55)
    ["id"]=>
    int(3)
  }
  [2]=>
  object(stdClass)#13 (3) {
    ["jsonrpc"]=>
    string(3) "2.0"
    ["result"]=>
    float(14.3)
    ["id"]=>
    int(4)
  }
}

```

case of 2)

```
array(2) {
  [0]=>
  object(stdClass)#8 (3) {
    ["jsonrpc"]=>
    string(3) "2.0"
    ["result"]=>
    int(110)
    ["id"]=>
    int(2)
  }
  [1]=>
  object(stdClass)#12 (3) {
    ["jsonrpc"]=>
    string(3) "2.0"
    ["result"]=>
    float(14.3)
    ["id"]=>
    int(3)
  }
}

```

and finally case of 3) the `$responseArray` will contain nothing so `NULL`

\#How do I use the server? You can reach the full sample application source @ `sample` directory. *Step by step tuturial soon.*\##Implementing service First of all, your service implementation must inherited from `Service` **This is necessary for all service**, because the `JsonRpcServer` will work with `Service` methods to detect callable methods and their parameters with [PHP reflection](http://php.net/manual/en/book.reflection.php)The client only can reach that method which has a block comment exactly with this content :

```
/* @JsonRpcMethod*/

```

The first space after `/*` is very important, because the reflection can not parse the comment winthout it. But, the below sample correct yet, because `Service` using [`strstr`](http://jp.php.net/manual/en/function.strstr.php) detecting the `@JsonRpcMethod` annotation.

```
/**
* @JsonRpcMethod which is ...
*/

```

For example, if you have some public method in `MathServiceImpl`, which not have any block comment with `@JsonRpcMethod` annotation, the client can not reach it.

**MathServiceImpl.php**

```
class MathServiceImpl extends JsonRpcService {
/** @JsonRpcMethod*/
public function add($aValue,$bValue) {
	return $aValue+$bValue;
}
/** @JsonRpcMethod*/
public function divide($aValue,$bValue) {
	return $aValue/$bValue;
}
/** @JsonRpcMethod*/
public function subtract($aValue,$bValue) {
	return $aValue-$bValue;
}
public function notCallableByRpcAlthoughItsPublic($name) {
	return $name;
    }
}

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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

Every ~543 days

Total

4

Last Release

2087d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7407146?v=4)[acgrid](/maintainers/acgrid)[@acgrid](https://github.com/acgrid)

---

Top Contributors

[![acgrid](https://avatars.githubusercontent.com/u/7407146?v=4)](https://github.com/acgrid "acgrid (8 commits)")[![bgli100](https://avatars.githubusercontent.com/u/7760499?v=4)](https://github.com/bgli100 "bgli100 (3 commits)")[![Pozo](https://avatars.githubusercontent.com/u/194902?v=4)](https://github.com/Pozo "Pozo (1 commits)")

---

Tags

web servicejsonrpc

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/guzzle

Guzzle is a PHP HTTP client library

23.4k991.0M31.1k](/packages/guzzlehttp-guzzle)[php-curl-class/php-curl-class

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

3.3k9.5M353](/packages/php-curl-class-php-curl-class)[srmklive/paypal

Laravel plugin For Processing Payments Through Paypal Express Checkout. Can Be Used Independently With Other Applications.

1.1k3.8M26](/packages/srmklive-paypal)[eightpoints/guzzle-bundle

Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony. Comes with easy and powerful configuration options and optional plugins.

45912.1M55](/packages/eightpoints-guzzle-bundle)[datto/json-rpc

Fully unit-tested JSON-RPC 2.0 for PHP

1951.3M14](/packages/datto-json-rpc)[denpa/php-bitcoinrpc

Bitcoin JSON-RPC client based on GuzzleHttp

284217.4k4](/packages/denpa-php-bitcoinrpc)

PHPackages © 2026

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