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

ActiveLibrary[API Development](/categories/api)

gruposinternet/json-rpc-php
===========================

JSON-RPC 2.0 Client/Server library for PHP

v1.0.x-dev(4y ago)0238BSD-3-ClausePHPPHP &gt;=5.3.0

Since Jan 17Pushed 4y agoCompare

[ Source](https://github.com/GruposInternet/json-rpc-php)[ Packagist](https://packagist.org/packages/gruposinternet/json-rpc-php)[ Docs](https://github.com/GruposInternet/json-rpc-php)[ RSS](/packages/gruposinternet-json-rpc-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

[﻿JSON-RPC 2.0](http://www.jsonrpc.org/spec.html) Client/Server library for PHP ###Requirements PHP 5.2.6+

\###Used predefined classes and interfaces

- [ReflectionClass](http://www.php.net/manual/en/class.reflectionclass.php) @ `lib/server/Service`
- [ReflectionMethod](http://www.php.net/manual/en/class.reflectionmethod.php) @ `lib/server/Service`
- [Exception](http://www.php.net/manual/en/class.exception.php) @ `lib/server/JsonRpcExceptions`

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

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

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

1582d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8267217?v=4)[Grupos Internet Ltda.](/maintainers/gruposinternet)[@GruposInternet](https://github.com/GruposInternet)

---

Top Contributors

[![gsalvati](https://avatars.githubusercontent.com/u/4029571?v=4)](https://github.com/gsalvati "gsalvati (4 commits)")[![Pozo](https://avatars.githubusercontent.com/u/194902?v=4)](https://github.com/Pozo "Pozo (1 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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