PHP code example of crayoon / hyperf-grpc

1. Go to this page and download the library: Download crayoon/hyperf-grpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

crayoon / hyperf-grpc example snippets


return [
    'scan' => [
        'paths' => [
            BASE_PATH . '/app',
        ],
        'ignore_annotations' => [
            'mixin',
        ],
        'class_map' => [
            \Google\Protobuf\Internal\DescriptorPool::class => BASE_PATH.'/vendor/crayoon/hyperf-grpc/class_map/Protobuf/DescriptorPool.php'
        ]
    ]
];

    'servers' => [
        [
            'name' => 'grpc',
            'type' => Server::SERVER_BASE,
            'host' => '0.0.0.0',
            'port' => 9501,
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_RECEIVE => [\Crayoon\HyperfGrpc\Server\StreamServer::class, 'onReceive']
            ],
        ],
        ...
    ],

// config/routes.php
// 路由使用助手类注册
GrpcHelper::RegisterRoutes(function () {
    // 在此处添加路由
    Router::addGroup('/goods.v1.Goods', function () {
        Router::post('/info', [\App\Controller\Grpc\GoodsController::class, "info"]);
        ...
    });
    ...
}, 'grpc', [], true);

php bin/hyperf.php vendor:publish crayoon/hyperf-grpc