hetao29 / php-grpc-server-thrift
The php grpc server framework with thrift and DO NOT use any 3rd libraries.
1.0.0
2022-01-04 10:19 UTC
Requires
- apache/thrift: ~v0.15.0
README
The php grpc server framework with thrift and DO NOT use any 3rd libraries.
Architecture
gRPC Client => nginx => php-fpm => this framework => custom services
Usage
- install with composer
composer require "hetao29/php-grpc-server-thrift:1.0.0"
- use in php file, like samples/www/index.php
<?php define("ROOT", dirname(__FILE__)."/../"); define("ROOT_LIBS", ROOT."/libs"); define("ROOT_SERVICE", ROOT."/service"); define("ROOT_PROTO_GENERATED", ROOT."/thrift_out/"); require_once(ROOT_LIBS."/vendor/autoload.php"); GRpcServer::$serviceDir=ROOT_SERVICE; GRpcServer::$defDir=ROOT_PROTO_GENERATED; if(($r=GRpcServer::run())!==false){ }
Write App Services
- gen thrift to php files
make gen
- write gRPC Server in services dir like helloworld
<?php namespace Test\HelloThrift; class HelloServiceHandler implements HelloServiceIf { public function sayHello($username) { return "Hello ".$username.", how are u?"; } }
- test
php www/client.php