1. Go to this page and download the library: Download mix/json-rpc library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mix / json-rpc example snippets
class Calculator
{
public const NAME = "php.micro.jsonrpc.calculator.Calculator";
public function Sum(int $a, int $b): int
{
return array_sum([$a, $b]);
}
}
$dialer = new \Mix\JsonRpc\Client\Dialer();
$conn = $dialer->dial('127.0.0.1', 9234);
$request = (new \Mix\JsonRpc\Factory\RequestFactory)->createRequest('Calculator.Sum', [1, 3], 100001)
$response = $conn->call($request);
var_dump($response);
$dialer = new \Mix\JsonRpc\Client\Dialer([
'registry' => new \Mix\Micro\Etcd\Registry('http://127.0.0.1:2379/v3'),
]);
$conn = $dialer->dialFromService('php.micro.jsonrpc.calculator');
$request = (new \Mix\JsonRpc\Factory\RequestFactory)->createRequest('Calculator.Sum', [1, 3], 100001)
$response = $conn->call($request);
var_dump($response);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.