安装
composer require fendui/laravel-hprose dev-master
配置
在 config/app.php
注册 HproseServiceProvider
'providers' => [ ..... \fendui\HproseServiceProvider::class ]
创建配置和demo路由文件
php artisan vendor:publish --provider="fendui\HproseServiceProvider"
服务端 方法注入和类注入
\fendui\Facades\HproseRoute::add(function () { return 'service hello'; }, 'hello'); \fendui\Facades\HproseRoute::add(\fendui\demoService::class);
启动rpc服务
php artisan hprose:socket
客户端调用
$uris =['tcp://127.0.0.1:1314']; $client = new \fendui\Clients\SocketClient($uris, false); $client->hello() $client->fendui_demoService->kan() 需要配置配置 'client' => [ 'tcp_uris' => [ 'tcp://127.0.0.1:1314', ], 'async' => false ], app('hprose.socket.client')->hello()
demo 查看注册的方法
http://127.0.0.1:8000/rpc
可以通过路由查看调用方式
http://127.0.0.1:8000/rpc/kan http://127.0.0.1:8000/rpc/demo/say http://127.0.0.1:8000/rpc/demo/kan http://127.0.0.1:8000/rpc/demo/can