DEV Community

Jhonatan Morais
Jhonatan Morais

Posted on

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
Enter fullscreen mode Exit fullscreen mode
  1. That will automatically from docker hub and set your containers up.
  2. Now go inside the php container:
docker exec -it php sh
Enter fullscreen mode Exit fullscreen mode
  1. Once inside the container you can use the grpc-generate.sh to build the static files:
sh grpc-generate.sh
Enter fullscreen mode Exit fullscreen mode
  1. And finally, execute the php clients examples:
php src/client-grpc.php #output: Unary call, Server answer: Hello Jhonatan 
Enter fullscreen mode Exit fullscreen mode
php src/server-stream-grpc.php #output: server stream server answer 10 messages 
Enter fullscreen mode Exit fullscreen mode
php src/client-stream-grpc.php #output: client streaming server answer after all requests 
Enter fullscreen mode Exit fullscreen mode
php src/open-stream-grpc.php #output: bi-diretional streamingm server answer after each requests   
Enter fullscreen mode Exit fullscreen mode

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

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay