Home  >  Article  >  PHP Framework  >  Share a useful Laravel extension (laravel-hprose)

Share a useful Laravel extension (laravel-hprose)

藏色散人
藏色散人forward
2021-07-12 14:20:401998browse

This article will share with you a useful Laravel extension (laravel-hprose), which is a Laravel extension developed based on hprose/hprose-php.

Share a useful Laravel extension (laravel-hprose)

Laravel extension developed based on hprose/hprose-php: laravel-hprose

https://github.com/fendui/laravel-hprose

Installation

composer require fendui/laravel-hprose dev-master

Configuration

Register HproseServiceProvider inconfig/app.php

'providers' => [
    .....
    \fendui\HproseServiceProvider::class
 ]

Create configuration and demo routing files

php artisan vendor:publish --provider="fendui\HproseServiceProvider"

Server-side method injection and class injection

\fendui\Facades\HproseRoute::add(function () {
    return 'service hello';
}, 'hello');

\fendui\Facades\HproseRoute::add(\fendui\demoService::class);

Start rpc service

php artisan hprose:socket

Client call

$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 View registered method

http://127.0.0.1:8000/rpc

You can view the calling method through routing

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

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of Share a useful Laravel extension (laravel-hprose). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete