Hyperf jsonrpc

依赖的 composer 包

composer require hyperf/json-rpc

composer require hyperf/rpc-server

composer require hyperf/rpc-client

composer require hyperf/service-governance

composer require hyperf/service-governance-consul

composer require hyperf/service-governance-nacos

`

复制代码
<?php

namespace App\JsonRpc;

use Hyperf\RpcServer\Annotation\RpcService;

/**
 * 注意,如希望通过服务中心来管理服务,需在注解内增加 publishTo属性 值为consul, protocol是协议,默认是jsonrpc-http, 这里演示TCP协议 故使用 jsonrpc
 * @RpcService(name="FooService ", protocol="jsonrpc", server="jsonrpc-tcp", publishTo="consul")
 */
class FooService implements FooServiceInterface
{
    /**
     * @inheritDoc
     */
    public function hello()
    {
        return 'This is Foo JsonRpc Service.';
    }
}

配置hyperf服务启动 `/conifg/autoload/server.php` 这里演示TCP协议

复制代码
。。。

[

    'name' => 'jsonrpc-tcp',

    'type' => \Hyperf\Server\Server::SERVER_BASE,

    'host' => '0.0.0.0',

    'port' => 9503,

    'sock_type' => SWOOLE_SOCK_TCP,

    'callbacks' => [

        \Hyperf\Server\Event::ON_RECEIVE => [\Hyperf\JsonRpc\TcpServer::class, 'onReceive'],

    ],

    'settings' => [

        'open_eof_split' => true,

        'package_eof' => "\r\n",

        'package_max_length' => 1024 * 1024 * 2,

    ],

],

配置注册中心 /conifg/autoload/services.php

复制代码
return [
    'enable'    => [
        // 开启服务发现
        'discovery' => true,
        // 开启服务注册
        'register'  => true,
    ],
    // 服务消费者相关配置
    'consumers' => [],
    // 服务提供者相关配置
    'providers' => [],
    // 服务驱动相关配置
    'drivers'   => [
        'consul' => [
            
        ],
        'nacos' => [
        
        ],
    ],
];
相关推荐
爱隐身的官人10 小时前
ctfshow - web - 命令执行漏洞总结(二)
php·命令执行
悠悠~飘1 天前
php简介(第一天打卡)
php
久绊A1 天前
Hydra-SSH 破解安全防范
开发语言·php
黑白世界46481 天前
开源分享: php-tools php gui的一次尝试
后端·php
2503_928411561 天前
9.8 ajax+php基础语法
ajax·okhttp·php
普通网友1 天前
支持二次开发的代练App源码:订单管理、代练监控、安全护航功能齐全,一站式解决代练护航平台源码(PHP+ Uni-app)
安全·uni-app·php
yenggd2 天前
centos系统apache支持php配置
centos·php·apache
ytttr8732 天前
PHP中各种超全局变量使用的过程
开发语言·php
名誉寒冰2 天前
TCP, 三次握手, 四次挥手, 滑动窗口, 快速重传, 拥塞控制, 半连接队列, RST, SYN, ACK
网络·tcp/ip·php
m0_738120722 天前
CTFshow系列——PHP特性Web97-100
开发语言·安全·web安全·php·ctfshow