PHP code example of raoptimus / yii2-jsonrpc2

1. Go to this page and download the library: Download raoptimus/yii2-jsonrpc2 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/ */

    

raoptimus / yii2-jsonrpc2 example snippets


return [
    //....
    'components' => 
        'jsonrpc' => [
            'class' => raoptimus\jsonrpc2\Connection::class,
            'hostname' => 'localhost',
            'port' => 8666,
        ],
];

return [
    //....
    'components' => 
        'jsonrpc' => [
            'class' => raoptimus\jsonrpc2\Connection::class,
            'unixSocket' => '/tmp/jsonrpc2.sock',
            'spec' => raoptimus\jsonrpc2\Connection::SPEC_2_0,
        ],
];

$rpc = \Yii::$app->get('jsonrpc');
$method = "SomeMethodName";
$param = "SomeEnterParam";
$request = $rpc->createRequest($method, [$param]);
$rpc->sendRequest($request);
$result = $rpc->readResponse()->result;
//or
$result = $rpc->$method($param);