PHP code example of ptcx / jsonrpc-client

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

    

ptcx / jsonrpc-client example snippets




nt = new JRClient\Client('tcp', '127.0.0.1:8888');

$result = $client->call('Arith.Multiply', ['A' => 3, 'B' => 4], 1000);
if ($result['error']) {
    echo $result['errorMsg'] . "\n";
} else {
    var_dump($result['data']);
}

$result = $client->call('Arith.Divide', ['A' => 10, 'B' => 4], 2000);
if ($result['error']) {
    echo $result['errorMsg'] . "\n";
} else {
    var_dump($result['data']);
}

$result = [
    'error' => false    // bool,socket错误,比如超时、发送、接收错误,不表示golang服务调用的error错误
    'errorMsg' => ''    // 当error为true时,错误信息
    'data' => []        // golang服务器返回的jsonrpc数据
]