PHP code example of connor / rpc-client

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

    

connor / rpc-client example snippets



//配置不同的handler来处理
$config = [
//        'handler' => new \GuzzleHttp\Handler\StreamHandler(),
//    'handler' => new \CClehui\RpcClient\GuzzleHandler\StreamSocketHandler(),
    'handler' => new \CClehui\RpcClient\GuzzleHandler\SocketHandler(),
];

//同步调用demo
$url = 'http://0.0.0.0/temp/test.php;
$params = [];
$rpc_client = new \CClehui\RpcClient\HttpRpcClientUtil();
$rpc_client->setGuzzleClientConfig($config);
$res = $rpc_client->callRemote($url, $params);

//异步调用demo (promise机制)
$url = 'http://0.0.0.0/temp/test.php';
$params = [];
$promises = [];
$rpc_client = new \CClehui\RpcClient\HttpRpcClientUtil();();
$rpc_client->setGuzzleClientConfig($config);

for ($i = 1; $i <= 2; $i++) {
    $promises[$i] = $rpc_client->callRemote($url, $params, 'GET', [], true);
}

$result_list = \GuzzleHttp\Promise\settle($promises)->wait();

foreach($result_list as $key => $item) {
    $response = $item['value'];
    
    $response = (string)$response->getBody();
    echo $response . "\n";
}