Slide 1

Slide 1 text

SEPTEMBER 18 -19, 2025 - LILLE, FRANCE & ONLINE Opening Keynote: Enhance Your API Platform APIs With Go Thanks to FrankenPHP

Slide 2

Slide 2 text

✔ API Platform creator ✔ FrankenPHP and Mercure creator ✔ PHP and Symfony maintainer ✔ Founder at Les-Tilleuls.coop Kévin Dunglas dunglas.dev

Slide 3

Slide 3 text

Web and cloud experts https:/ /github.com/sponsors/api-platform

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

10 Years of API Platform!

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

10 Years of Community

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Today Is Also Nils Birthday 🎂

Slide 10

Slide 10 text

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 🍻

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

One Framework, Multiple API Architectural Styles

Slide 14

Slide 14 text

One Structure, Multiple architectures namespace App\ApiResource; use ApiPlatform\Metadata\ApiResource\ApiResource; #[ApiResource] class Book { public ?int $id = null; /** The title of this book */ public string $title; }

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

gRPC

Slide 18

Slide 18 text

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.

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Typical gRPC Architecture

Slide 22

Slide 22 text

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; }

Slide 23

Slide 23 text

gRPC PHP Server

Slide 24

Slide 24 text

gRPC and PHP: Server 😱

Slide 25

Slide 25 text

FrankenPHP to the Rescue

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

FrankenPHP gRPC

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

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!

Slide 34

Slide 34 text

Create a Go Module go mod init \ example.com/mygrpcserver

Slide 35

Slide 35 text

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; }

Slide 36

Slide 36 text

Generate the Go code protoc \ --go_out=.\ --go_opt=paths=source_relative \ --go-grpc_out=. \ --go-grpc_opt=paths=source_relative \ helloworld/helloworld.proto

Slide 37

Slide 37 text

Register Your gRPC Server func init() { phpGrpc.RegisterGrpcServerFactory(func() *grpc.Server { s := grpc.NewServer() pb.RegisterGreeterServer(s, &server{}) reflection.Register(s) return s }) }

Slide 38

Slide 38 text

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 }

Slide 39

Slide 39 text

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)) {}

Slide 40

Slide 40 text

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)) {}

Slide 41

Slide 41 text

The Caddyfile { frankenphp grpc { address :50051 # Optional worker grpc-worker.php # Optional min_threads 50 # Optional, defaults to runtime.NumCPU() } }

Slide 42

Slide 42 text

Build and Run CGO_ENABLED=1 \ CGO_CFLAGS="$(php-config --includes)" \ CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" \ xcaddy build ./caddy run

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

FOLLOW ME! @dunglas dunglas.dev / les-tilleuls.coop / api-platform.com Thank you! Any questions?