PHP code example of fullpipe / php-json-rpc-client
1. Go to this page and download the library: Download fullpipe/php-json-rpc-client 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/ */
fullpipe / php-json-rpc-client example snippets
use Fullpipe\RpcClient\Client;
use Fullpipe\RpcClient\Error\AppError;
use Fullpipe\RpcClient\Error\MethodNotFound;
use Fullpipe\RpcClient\Error\InvalidParams;
...
$client = new Client('https://api.server/rpc', [
'retries' => 0,
'delay' => 500,
'http' => ['timeout' => 1],
]);
// Simple call
$userData = $client->call('user.get', ['id' => 123]);
// Simple call with single retry
$userData = $client->retryOnce()->call('user.get', ['id' => 123]);
// Call and catch application error
try {
$userData = $client->call('user.get', ['id' => 123]);
} catch (AppError $e) {
if ($e->getCode() !== 404) {
throw $e;
}
$userData = $this->createNewUser();
} catch (MethodNotFound | InvalidParams $e) {
$this->sentry->catchException($e);
}