Upgrade to Pro — share decks privately, control downloads, hide ads and more …

php grpc-client in phpcon2018

shmurakami
December 15, 2018

php grpc-client in phpcon2018

About grpc-client and use case of that for PHP

shmurakami

December 15, 2018
Tweet

More Decks by shmurakami

Other Decks in Technology

Transcript

  1. © Chatwork 1SPUPDPM#VGGFSTTBNQMF syntax = “proto3"; message Person { string

    name = 1; string email = 2; enum PhoneType { MOBILE = 0; HOME = 1; } message PhoneNumber { string number = 1; PhoneType type = 2; } } service GreetingService { rpc greet (Person) returns (stream PersonResponse); }
  2. © Chatwork QSPUPDίϚϯυαϯϓϧ $ protoc \ --proto_path=./proto \ --php_out=./dest \

    --grpc_out=./dest \ --plugin=protoc-gen-grpc=./grpc/bins/opt/grpc_php_plugin \ ./proto/sample.proto
  3. © Chatwork ੜ੒ϑΝΠϧ $ tree dest ├── GPBMetadata │ └──

    Sample.php ├── GreetingServiceClient.php ├── Person │ ├── PhoneNumber.php │ └── PhoneType.php ├── Person.php proto └── sample.proto syntax = “proto3"; message Person { string name = 1; string email = 2; enum PhoneType { MOBILE = 0; HOME = 1; } message PhoneNumber { string number = 1; PhoneType type = 2; } } service GreetingService { rpc greet (Person) returns (stream PersonResponse); }
  4. © Chatwork ੜ੒ϑΝΠϧ <?php class Person extends \Google\Protobuf\Internal\Message { private

    $name = ''; private $email = ''; public function __construct($data = NULL) { /*...*/ } public function getName() { return $this->name; } public function setName($var) { /*...*/ } public function getEmail() { return $this->email; } public function setEmail($var) { /*...*/ } }
  5. © Chatwork ੜ੒ϑΝΠϧ <?php // GENERATED CODE -- DO NOT

    EDIT! namespace ; class GreetingServiceClient extends \Grpc\BaseStub { public function __construct($hostname, $opts, $channel = null) { parent::__construct($hostname, $opts, $channel); } public function greet(\Person $argument, $metadata = [], $options = []) { return $this->_serverStreamRequest('/GreetingService/greet', $argument, ['\PersonResponse', 'decode'], $metadata, $options); } }
  6. © Chatwork %PDLFSGJMFྫ FROM amazonlinux:2018.03 RUN yum update -y &&

    \ yum install -y \ # grpc dependencies git gcc gcc48-c++ autoconf automake libtool unzip which wget # download protoc RUN mkdir /opt/protoc && \ wget -O /opt/protoc/protoc.zip https://github.com/protocolbuffers/protobuf/ releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \ && unzip -d /opt/protoc /opt/protoc/protoc.zip \ && rm /opt/protoc/protoc.zip # build grpc_php_plugin RUN git clone https://github.com/grpc/grpc /opt/grpc \ && cd /opt/grpc \ && git submodule update --init \ && cd /opt/grpc/third_party/protobuf \ && sh autogen.sh \ && cd /opt/grpc \ && make grpc_php_plugin
  7. © Chatwork H31$௨৴ ˔H31$௨৴ॲཧͷ࣮ମ ˓H31$FYUFOTJPO$ Ͱ࡞ΒΕ͓ͯΓ1)1֦ுΛΠϯε τʔϧ͢Δ ˓1&$-Ͱ഑෍͞Ε͍ͯΔ HSQD 

    ˔HSQDϥΠϒϥϦ ˓HSQD֦ுΛૢ࡞͢ΔͨΊͷϥΠϒϥϦ ˓$PNQPTFSͰ഑෍͞Ε͍ͯΔ HSQDHSQD
  8. © Chatwork 3FRVFTU3FTQPOTF4FSJBMJ[FS ˔1SPUPDPM#VGGFSTͷ1)1֦ு QSPUPCVG ͕ͦΕ ˓1&$- QSPUPCVG ΋͘͠͸ ˓$PNQPTFS

    HPPHMFQSPUPCVG Ͱఏڙ͞Ε͍ͯΔ ˓֦ுͷํ͕$PNQPTFSΑΓύϑΥʔϚϯε͕༏Ε͍ͯΔ ˙֦ுΛ࢖͏Α͏ʹ͢Δͱ1IQ4UPSNͰίʔυิ׬͕ ޮ͔ͳ͍ͷͰSFRVJSFEFWͰೖΕ͍ͯΔ
  9. © Chatwork ґଘίϯϙʔωϯτͷόʔδϣϯ ˔HSQD QSPUPCVG QSPUPDͷόʔδϣϯޓ׵ੑΛอͭඞཁ͕͋Δ ˓ͦΕͧΕͷೖखܦ࿏͕ҧ͏ ˓1&$- $PNQPTFS (JU)VCSFMFBTFQBHF

    ˓1)1࣮ߦ࣌ͰͷΤϥʔ·Ͱ໰୊ʹؾͮ͘λΠϛϯά͕ແ͍ ˙Τϥʔʹͳͬͯ΋ϥΠϒϥϦͷத·ͰίʔυΛݟʹߦ ͔ͳ͍ͱԿ͕͓͔͍͔͠෼͔Βͳ͍