Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing FrankenPHP gRPC

Introducing FrankenPHP gRPC

Theses slides were presented during the opening keynote of the API Platform Conference. They unveil an experimental gRPC extension for the FrankenPHP application server, .

The extension enables developers to build high-performance gRPC servers using PHP, leveraging the power of Go's native gRPC library.

Avatar for Kévin Dunglas

Kévin Dunglas

September 18, 2025
Tweet

More Decks by Kévin Dunglas

Other Decks in Programming

Transcript

  1. SEPTEMBER 18 -19, 2025 - LILLE, FRANCE & ONLINE Opening

    Keynote: Enhance Your API Platform APIs With Go Thanks to FrankenPHP
  2. ✔ API Platform creator ✔ FrankenPHP and Mercure creator ✔

    PHP and Symfony maintainer ✔ Founder at Les-Tilleuls.coop Kévin Dunglas dunglas.dev
  3. 10 Years of Community ✔ 14k stargazers on GitHub ✔

    921 code and docs contributors ✔ 5.7k people on Slack ✔ Symfony and Laravel support ✔ Gave rise to Mercure, FrankenPHP, and many Symfony components
  4. The Biggest API Platform Conference Ever ✔ Sold out: we

    are 400 in Lille ✔ 200+ people online from all over the world ✔ For the 1st time: 3 tracks! ✔ 35 incredible speakers ✔ Stunning booths from sponsors and partners ✔ Huge parties 🍻
  5. Remembering Ryan Weaver (1984-2025) ✔ The Voice of SymfonyCasts: Ryan’s

    engaging and humorous screencast series on API Platform made complex topics accessible and fun for thousands of developers worldwide. ✔ Significant API Platform Contributor: He was instrumental in shaping the framework, dedicating his talent to writing important features and improving the developer experience. ✔ Our Conference Speaker: He shared his knowledge and enthusiasm from this very stage, bringing our community closer together. A Lasting Legacy
  6. Hydra OpenAPI HAL JSON:API GraphQL Machine accessible hypermedia API (REST/HATEOS)

    2015, me, f55cfce Machine-readable interface definition for web services 2016, Hamza Amrouche, #591 Simple REST/HATEOAS format 2016, Hamza Amrouche, #608 Set of conventions for JSON-based web APIs 2017, Baptiste Meyer, #1175 Advanced query language for APIs 2017, Alan Poulain, #1358 Mercure Async API protocol, data is pushed to clients in real time 2018, me, #2282 Supported architectures
  7. gRPC gRPC (gRPC Remote Procedure Calls) is a modern, open-source

    framework for building high-performance APIs. Unlike traditional REST APIs that use JSON over HTTP, gRPC uses a more efficient binary format called Protocol Buffers (Protobuf) over HTTP/2.
  8. gRPC: Key Features ✔ Fast & Efficient: The use of

    Protobuf and HTTP/2 results in significantly faster communication and lower latency ✔ Strongly-Typed: Defines a strict schema for messages, preventing errors and ensuring data consistency ✔ Language Agnostic: Supports multiple programming languages, making it ideal for microservices where different services might be built with different technologies
  9. gRPC: Use cases ✔ Microservices: internal communication between services written

    in different languages ✔ IoT: efficient binary protocol, perfect for connected devices and objects ✔ Critical components: optimized for resiliency and speed
  10. gRPC Service Definition // The greeting service definition. service Greeter

    { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} } // The request message containing the user's name. message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; }
  11. FrankenPHP A modern app server for PHP apps: ✔ Replaces

    NGINX+FPM or Apache+mod_php ✔ Built for easy deployments: ◦ compatible with Docker, can embed your app in the binary! ✔ The fastest PHP engine (in worker mode) ✔ 103 Early Hints, Mercure, Vulcain… ✔ Compatible with all existing PHP apps ✔ Included in the API Platform distribution
  12. FrankenPHP Extensions ✔ New in FrankenPHP 1.8 ✔ Write PHP

    extensions in Go! ✔ High-performance concurrency with goroutines ✔ Use the numerous existing Go libraries ✔ Share data between requests ✔ Run code entirely concurrently
  13. Extensions Features ✔ Helper to register the PHP extension ✔

    Helpers to convert Zend Engine types to Go types (and vice versa) ✔ Code generator to generate the C boilerplate code ✔ New in the upcoming FrankenPHP version, PHP workers for extension ◦ Ex: in-process Symfony Messenger worker
  14. FrankenPHP gRPC ✔ Run a high performance gRPC server with

    FrankenPHP ✔ Write gRPC service handlers in PHP: handlers run in a worker loop ✔ Write gRPC service handlers in Go ✔ Write gRPC service handlers in a mix of PHP and Go 🤯 ✔ All features supported by the gRPC for Go library ✔ Entirely written in Go, no C code! ✔ API Platform compatibility!
  15. Create a Protobuf Definition syntax = "proto3"; option go_package =

    "example.com/mygrpcserver/helloworld"; package helloworld; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }
  16. Generate the Go code protoc \ --go_out=.\ --go_opt=paths=source_relative \ --go-grpc_out=.

    \ --go-grpc_opt=paths=source_relative \ helloworld/helloworld.proto
  17. Register Your gRPC Server func init() { phpGrpc.RegisterGrpcServerFactory(func() *grpc.Server {

    s := grpc.NewServer() pb.RegisterGreeterServer(s, &server{}) reflection.Register(s) return s }) }
  18. Write Your Service in Go func (s *server) SayHello(_ context.Context,

    in *pb.HelloRequest) (*pb.HelloReply, error) { // Convert the request to a map[string]any var phpRequest map[string]any mapstructure.Decode(in, &phpRequest) // Call the PHP code, pass the map as a PHP associative array phpResponse := phpGrpc.HandleRequest(phpRequest) // Convert the PHP response (a map) back to a HelloReply struct var response pb.HelloReply mapstructure.Decode(phpResponse.(frankenphp.AssociativeArray).Map, &response) return &response, nil }
  19. Write Your Handler in PHP // grpc-worker.php $handler = static

    function (array $request): array { // Do something with the gRPC request return ['message' => "Hello, {$request['Name']}"]; }; while (\frankenphp_handle_request($handler)) {}
  20. Alternative: API Platform Handler // api-platform-grpc-worker.php // Require Composer’s autoloader,

    boot API Platform, retrieve services… $handler = static function (array $grpcRequest): array { $request = $objectMapper->map((object) $grpcRequest, MyRequest::class); $reply = $apiPlatformProcessor->process($request); return (array) $reply; }; while (\frankenphp_handle_request($handler)) {}
  21. The Caddyfile { frankenphp grpc { address :50051 # Optional

    worker grpc-worker.php # Optional min_threads 50 # Optional, defaults to runtime.NumCPU() } }
  22. Next Steps ✔ Code already available on github.com/dunglas/frankenphp-grpc ✔ Polish

    the FrankenPHP feature (almost done) ✔ Generate the code of Go handler ✔ Generate the .proto file from API Platform resource classes ✔ Create a dedicated API Platform provider and processor (easy pick) ✔ Help welcome, API Platform = community