安裝
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