Skip to content

ssfyn/php-grpc-server-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP gRPC Server Example

This is a simple demo, used to demonstrate how to use PHP as a gRPC service.

Minimum PHP Version

0. Prepare

When these installations encounter problems, please refer to: https://grpc.io/docs/quickstart/php.html

Install protoc

git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
cd grpc
git submodule update --init
make
sudo make install

Install PHP Protoc plugin

git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
cd grpc
git submodule update --init
make grpc_php_plugin

Install ext-protobuf

pecl install protobuf

Install ext-grpc

pecl install ext-grpc

1. Init project

Composer

composer install

Protoc

protoc --php_out=./pb-src --grpc_out=./pb-src --plugin=protoc-gen-grpc=$(which grpc_php_plugin) ./protos/HelloWorld.proto

2. Startup server

require_once __DIR__.'/vendor/autoload.php';

$server = new \Dev\Fyn\Server('0.0.0.0:50051');
$server->serve();

3. Using client call gRPC Service

require_once __DIR__.'/vendor/autoload.php';

$client = new HelloWorldClient('127.0.0.1:50051',[
    'credentials'=>\Grpc\ChannelCredentials::createInsecure()
]);

$request = new SayHelloRequest();
$request->setName('fyn');

$call = $client->SayHello($request);
[$response, $status] = $call->wait();

echo "Code: ", $status->code,"\n";
echo "Details: ", $status->details,"\n";
echo "Reply: ", ($response?$response->getReply():null),"\n";

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published