An easy to use gRPC PHP client

Some weeks ago I wrote the series: How to start using grpc with PHP and now I want to share the repository with the docker image of the final grpc PHP client. it is self-conteined and docker based project it offers: A docker image to compile the grpc_php_plugin and protoc-29.0.0 from php 8.3 A sh file to generate the static code A valid example of using each of grpc services from server Please, like and share! How to use the client After cloning the repo, go to root project folder and execute to: docker compose up -d That will automatically from docker hub and set your containers up. Now go inside the php container: docker exec -it php sh Once inside the container you can use the grpc-generate.sh to build the static files: sh grpc-generate.sh And finally, execute the php clients examples: php src/client-grpc.php #output: Unary call, Server answer: Hello Jhonatan php src/server-stream-grpc.php #output: server stream server answer 10 messages php src/client-stream-grpc.php #output: client streaming server answer after all requests php src/open-stream-grpc.php #output: bi-diretional streamingm server answer after each requests Visit the repo4 and chech the implementation of each client call and adjust it to your needs

Mar 27, 2025 - 13:42
 0
An easy to use gRPC PHP client

Some weeks ago I wrote the series: How to start using grpc with PHP and now I want to share the repository with the docker image of the final grpc PHP client.

it is self-conteined and docker based project it offers:

  1. A docker image to compile the grpc_php_plugin and protoc-29.0.0 from php 8.3
  2. A sh file to generate the static code
  3. A valid example of using each of grpc services from server

Please, like and share!

How to use the client

  1. After cloning the repo, go to root project folder and execute to:
docker compose up -d
  1. That will automatically from docker hub and set your containers up.
  2. Now go inside the php container:
docker exec -it php sh
  1. Once inside the container you can use the grpc-generate.sh to build the static files:
sh grpc-generate.sh
  1. And finally, execute the php clients examples:
php src/client-grpc.php #output: Unary call, Server answer: Hello Jhonatan 
php src/server-stream-grpc.php #output: server stream server answer 10 messages 
php src/client-stream-grpc.php #output: client streaming server answer after all requests 
php src/open-stream-grpc.php #output: bi-diretional streamingm server answer after each requests   

Visit the repo4 and chech the implementation of each client call and adjust it to your needs