Download the PHP package huo-zi/laravel-yar-rpc-client without Composer
On this page you can find all versions of the php package huo-zi/laravel-yar-rpc-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package laravel-yar-rpc-client
Laravel YAR RPC Client
基于 Laravel 框架服务注册及门面的 YAR 客户端,提供优雅的 YAR RPC 服务调用。
功能特性
- 🚀 优雅的 RPC 调用方式,支持 Laravel Facade
- ⚡ 支持 HTTP Keep-Alive 持久连接
- 📝 自动生成类型提示完善的 Facade 类
- 🔧 灵活的全局配置和客户端级配置
- 🔄 支持多种序列化方式(PHP、JSON、MsgPack)
- ⏱️ 使用延迟加载(
DeferrableProvider接口)按需实例化提升性能
依赖要求
- PHP >= 7.3 || >= 8.0
- Laravel >= 5.8
- PHP YAR 扩展 (
ext-yar)
安装
配置
1. 发布配置文件
2. 配置 RPC 服务端
编辑 config/yar_client.php 文件:
使用
1. 生成 Facade
此命令会自动:
- 爬取服务端的 API 方法列表
- 在
App/Rpc/Clients/目录生成对应的 Facade 类
2. 调用 RPC 方法
3. 并发调用
支持并发调用多个 RPC 服务,提高请求效率:
3.1 魔术方法调用(推荐)
使用魔术方法调用:
3.2 使用 call() 方法调用
使用 call() 方法调用:
3.3 结果格式
并发调用特点:
- 所有请求同时发送,减少等待时间
- 自动处理错误,即使某个服务失败也不会影响其他服务
- 返回结果按
client.method格式组织,方便获取 - 支持链式调用,代码更加简洁
- 支持两种调用方式:魔术方法和 call() 方法
配置选项说明
| 配置项 | 默认值 | 说明 |
|---|---|---|
namespace |
App\Rpc\Clients\ |
Facade 类生成目录 |
options.timeout |
5000ms | 调用超时时间 |
options.connect_timeout |
1000ms | 连接超时时间 |
options.packager |
php |
序列化方式 |
options.persistent |
true |
是否启用持久连接 |
服务注册原理
服务提供者已实现 DeferrableProvider 接口,支持延迟加载:
延迟加载机制:
- 服务提供者实现了
provides()方法,返回服务标识列表 - 当首次调用某个 RPC Facade 时,Laravel 才会注册对应的服务提供者并实例化客户端
更新配置后的缓存清理
当你更新了 config/yar_client.php 中的客户端配置后,需要清理以下缓存文件:
注意: 在生产环境中更新 RPC 配置后,务必执行缓存清理,否则新配置不会生效。
License
MIT License
All versions of laravel-yar-rpc-client with dependencies
PHP Build Version
Package Version
Requires
php Version
^7.3|^8.0
ext-yar Version *
laravel/framework Version ~5.8|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0|~12.0
ext-yar Version *
laravel/framework Version ~5.8|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0|~12.0
The package huo-zi/laravel-yar-rpc-client contains the following files
Loading the files please wait ...