PHP code example of playtini / grpc-server-bundle

1. Go to this page and download the library: Download playtini/grpc-server-bundle 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/ */

    

playtini / grpc-server-bundle example snippets




namespace App\Calculator;

use Playtini\MainServiceName\Calculator\CalculatorInterface;
use Playtini\MainServiceName\Calculator\Result;
use Playtini\MainServiceName\Calculator\Sum;
use Spiral\GRPC;

class CalculatorService implements CalculatorInterface
{
    public function Sum(GRPC\ContextInterface $ctx, Sum $in): Result
    {
        return new Result([
            'result' => $in->getA() + $in->getB(), 
        ]);
    }
}
console
syntax="proto3";

package playtini;

option php_generic_services = true;
option php_namespace = "Playtini\\MainServiceName";
option php_metadata_namespace = "Playtini\\MainServiceName\\Meta";

import 'calculator.proto';
console
protoc /proto/base.proto \
        -I/proto -I/proto/base.proto proto/calculator.proto \
        --php_out=/proto/src \
        $(: 👇 custom plugin from roadrunner to generate server interface) \
        --php-grpc_out=/proto/src \
        $(: 👇 generates the client code) \
        --grpc_out=/proto/src \
        --plugin=protoc-gen-grpc=/protobuf/grpc/bins/opt/grpc_php_plugin \
        --proto_path /proto