PHP code example of jackmeng / laravel-rpc

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

    

jackmeng / laravel-rpc example snippets


$this->success([]);
$this->error('');

php artisan rpc_client

(new TestClient())->service('Demo')->list(1);

# Demo.php
class Demo extends \LaravelRcp\Client
{
    protected $server = 'test';
    public static function list($page=1)
    {
        return (new self())->method('list',compact('page'));
    } 
}

#调用
Demo::list()

"status"=>true, // 设置为true 表示开启rpc服务,会注册路由,客户端请设置为false
"root"=>[
    "dir"=>"app\RPC", // RPC服务的根目录
    "namespace"=>'App\\RPC\\', // RPC服务的命名空间
],
"database"=>[
    "connection"=>"default", // 服务端需要用到的数据库连接,客户端无需配置
    "prefix"=>"rpc_" // 数据表前缀
],
"prefix"=>"rpc", // 服务端路由前缀
"servers"=>[ // 客户端需配置此选项,用以注册服务端
    "test"=>[
        "domain"=>env('RPC_TEST_DOMAIN'), // 服务端域名
        "prefix"=>env('RPC_TEST_PREFIX'), // 路由前缀
        "appid"=>env('RPC_TEST_APPID'), // appid 在服务端获取,用于表示客户端id
        "secret"=>env('RPC_TEST_SECRET'), // secret 在服务端获取,用于通信签名及校验
    ]
]
shell
composer 录中没有laravel_rpc.php,请执行一下命令
php artisan vendor:publish --provider="LaravelRpc\\LaravelRPCProvider"
shell
# 发布数据库迁移文件
php artisan vendor:publish --tag=laravel_rpc_migration
# 执行数据库迁移文件
php artisan migration