Home > PHP Framework > Laravel > body text

Share a useful Laravel extension (laravel-hprose)

藏色散人
Release: 2021-07-13 08:59:16
forward
1962 people have browsed it

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
Copy after login

Installation

composer require fendui/laravel-hprose dev-master
Copy after login

Configuration

Register HproseServiceProvider inconfig/app.php

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

Create configuration and demo routing files

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

Server-side method injection and class injection

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

\fendui\Facades\HproseRoute::add(\fendui\demoService::class);
Copy after login

Start rpc service

php artisan hprose:socket
Copy after login

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()
Copy after login

demo View registered method

http://127.0.0.1:8000/rpc
Copy after login

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
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!