timostamm / protoc-h1-php-server
PHP utilities to implement protobuf services on a simple HTTP server
v2.0.0
2025-09-16 06:47 UTC
Requires
- php: ^8.0
- google/protobuf: ^3.10
- symfony/property-info: ^5.4 || ^6.4
Requires (Dev)
- phpunit/phpunit: ^9.6.20
- psr/container: ^1.0
- psr/log: ^1.1
- symfony/http-foundation: ^5.4 || ^6.4
Suggests
- ext-bcmath: Need to support JSON deserialization
- psr/container: To resolve service implementation from container
- psr/log: To handle requests
- symfony/http-foundation: To handle requests
README
PHP utilities to implement protobuf services on a simple HTTP server.
Supports all unary RPC calls over HTTP 1.
For auto-generated clients, see https://github.com/timostamm/protoc-h1-plugins
Let`s say you have this service defined in a proto file:
option php_generic_services = true;
service SearchService {
rpc Search (SearchRequest) returns (SearchResponse);
}
From this file, protoc generates a generic service interface
SearchServiceInterface.php
. You just implement this interface with your
business logic.
Then you can let HttpHandler
take care of request and response:
#[Route(path: '{serviceName}/{methodName}', methods: ['PUT'])] public function execute(RequestInterface $request, string $serviceName, string $methodName): Response { $resolver = new ServiceResolver(); $resolver->registerInstance( SearchServiceInterface::class, // the interface generated by protoc new SearchService() // your implementation of the interface ); $handler = new HttpHandler($resolver); // turn on details in error messages $handler->setDebug(true); // will log exception details, regardless of debug mode $handler->setLogger($myPsrLogger); return $handler->handle($serviceName, $methodName, $request); }