PHP code example of im050 / rpc-client

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

    

im050 / rpc-client example snippets


$host = "tcp://127.0.0.1:8099";

//实例化一个service工厂
$factory = \Im050\RpcClient\ClientBuilder::instance();
$factory->setHost($host);

//获取demoService实例
$demoService = $factory->get("App\\Lib\\DemoInterface");

//调用demoService的getUser方法
$results = $demoService->getUsers([1,2,3,4,5,6]);

//调用demoService的getUserByCond方法
$results2 = $demoService->getUserByCond(1, 1, "lin", 1.2);

//改变demoService版本号
$demoService->setVersion('1.0.1');

//调用demoService的getUsers方法
$results3 = $demoService->getUsers([1,2]);

var_dump($results, $results2, $results3);


class DemoServices extends \Im050\RpcClient\Services\Services
{
    /**
     * 定义接口
     *
     * @var string
     */
    public $interface = "App\\Lib\\DemoInterface";

    /**
     * 定义版本号
     *
     * @var string
     */
    public $version = '1.0.1';
}

//通过类的方式创建demoService实例
$demoServiceV2 = $factory->get(DemoServices::class);

//获取demoServiceV2的用户
$results4 = $demoServiceV2->getUser(1);