Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taoso/protoc-gen-grpc-php
protoc grpc plugin for PHP
https://github.com/taoso/protoc-gen-grpc-php
grpc grpc-php protoc-grpc-plugin
Last synced: about 2 months ago
JSON representation
protoc grpc plugin for PHP
- Host: GitHub
- URL: https://github.com/taoso/protoc-gen-grpc-php
- Owner: taoso
- License: mit
- Created: 2018-01-01T09:00:27.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-16T14:41:06.000Z (over 5 years ago)
- Last Synced: 2024-07-17T06:30:15.446Z (6 months ago)
- Topics: grpc, grpc-php, protoc-grpc-plugin
- Language: PHP
- Size: 51.8 KB
- Stars: 26
- Watchers: 3
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# protoc-gen-grpc-php
gRPC plugin and sdk for php.
## Installation
composer require lvht/grpc
## Generate PHP SDK
run the following command to generate php sdk for helloworld.proto
protoc --php_out=out --grpc-php_out=composer_name=grpc/hello:out \
--plugin=protoc-gen-grpc-php=./vendor/bin/protoc-gen-grpc-php \
./helloworld.protoyou will get
```
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`.Please see the `example/client.php` and `example/server.php` for more detail.
## Arguments
protoc-gen-grpc-php offer some arguments.
* 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.
### 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**.
### 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.
```
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 海涛"
}```