Skip to content

PHP utilities to implement protobuf services on a simple HTTP server

Notifications You must be signed in to change notification settings

timostamm/protoc-h1-php-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Protobuf RPC over HTTP 1 - PHP server

build Packagist PHP Version GitHub tag License

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

Lets 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( methods={"PUT"}, path="{serviceName}/{methodName}" )
 */
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);
}

About

PHP utilities to implement protobuf services on a simple HTTP server

Resources

Stars

Watchers

Forks

Packages

No packages published