2017 © Pedro Peláez
 

library grpc

image

lvht/grpc

  • Thursday, May 31, 2018
  • by lvht
  • Repository
  • 2 Watchers
  • 12 Stars
  • 481 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 12 Versions
  • 6 % Grown

The README.md

protoc-gen-grpc-php

gRPC plugin and sdk for php., (*1)

Installation

composer require lvht/grpc

Generate PHP SDK

run the following command to generate php sdk for helloworld.proto, (*2)

protoc --php_out=out --grpc-php_out=composer_name=grpc/hello:out \
    --plugin=protoc-gen-grpc-php=./vendor/bin/protoc-gen-grpc-php \
    ./helloworld.proto

you will get, (*3)

out
├── composer.json                   -- make sdk as a composer package
├── GPBMetadata
│   └── Helloworld.php
└── Helloworld
    ├── GreeterService.php          -- php interface for service
    ├── GreeterServiceTrait.php     -- generated service helper code
    ├── GreeterServiceStub.php      -- generated service stub code
    ├── HelloReply.php              -- message class generated by protoc
    └── HelloRequest.php            -- message class generated by protoc

For XXX service define in proto, you will get a XXX interface. The XXX interface has one implementation, XXXServiceStub for client side. And you need develop your own server side implementation using the XXXServerTrait., (*4)

Please see the example/client.php and example/server.php for more detail., (*5)

Arguments

protoc-gen-grpc-php offer some arguments., (*6)

  • composer_name set the generated code's package name
  • stub_trait add additional trait to the generated stub
  • stub_trait_only replace the default trait of the generated stub

Simple gRPC

Besides the standard gRPC, the generated code has two additional features., (*7)

gRPC over http/1.1

Set the use_http1 flag to true when you create a stub instance will let stub use http1.1 to transfer rpc data. Both grpc-status and grpc-message will be transfered as a normal http header instead of Trailers., (*8)

simple gRPC or sRPC

Set the Content-Type to application/json will let stub use a more simple mode to transfer rpc data. In the simple mode, only json is supported, and the message prefix must not be transfered. Both http/1 and http/2 are supported., (*9)

POST /helloworld.Greeter/SayHello HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 24
Content-Type: application/json
Host: localhost:8080
User-Agent: HTTPie/0.9.9
foo: bar

{
    "name": "海涛"
}

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 26
Date: Sat, 24 Feb 2018 08:09:20 GMT
Server: swoole-http-server
b-bin: 5L2g5aW9
content-type: application/json
grpc-status: 0

{
    "message": "Hello 海涛"
}

The Versions

31/05 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

31/05 2018

v2.1.3

2.1.3.0

  Sources   Download

MIT

The Requires

 

31/05 2018

v2.1.2

2.1.2.0

  Sources   Download

MIT

The Requires

 

03/04 2018

v2.1.1

2.1.1.0

  Sources   Download

MIT

The Requires

 

28/03 2018

v2.1.0

2.1.0.0

  Sources   Download

MIT

The Requires

 

24/02 2018

v2.0.0

2.0.0.0

  Sources   Download

MIT

The Requires

 

23/02 2018

dev-ctx

dev-ctx

  Sources   Download

MIT

The Requires

 

22/02 2018

v1.1.2

1.1.2.0

  Sources   Download

MIT

The Requires

 

30/01 2018

v1.1.1

1.1.1.0

  Sources   Download

MIT

The Requires

 

29/01 2018

v1.1.0

1.1.0.0

  Sources   Download

MIT

The Requires

 

20/01 2018

v1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

20/01 2018

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires