native: API, hot conﬁg reloading… ➔ Automatic HTTPS ➔ HTTP/2, HTTP/3, Early Hints… ➔ Extensible with modules: Mercure, Vulcain, OAuth, OIDC… ➔ Prod ready ➔ Written in Go 😻 Caddy: The New Kid on the Block
➔ Keep it in memory ➔ Process incoming requests without having to boot your app again ➔ Relies on goroutines and channels ➔ Compatible with Symfony Runtime and Laravel Octane (soon) ➔ Somewhat similar to RoadRunner ➔ Unlike RR, uses plain old superglobals
written in C ➔ php-src uses Zend Engine ◆ compiler (with Just In Time) ◆ executor (Virtual Machine) ➔ SAPIs ◆ Pass input from the web server to the PHP engine ◆ Pass output from the the PHP engine to the web server PHP Internals: the Basics
call C code ➔ Go and C ﬁles can be compiled in a single program ➔ The resulting binary can be static! ➔ The native package to call C code is called cgo ➔ Using cgo we can embed PHP in Caddy, Symfony CLI and other Go programs! C? Go? Cgo!
apps ➔ net/http: native package to create HTTP clients and servers ➔ Production-grade: optimized and secure ➔ Native HTTP/2 (HTTP/3 with a 3rd party lib) ➔ Used by Caddy, Symfony CLI, Kubernetes, Traeﬁk, Google, Cloudﬂare… net/http
a server and the PHP engine ➔ Use cgo to call PHP with data coming from Go’s HTTP messages ➔ Extract data from Go’s http.Request, pass it to PHP ➔ Write data generated by PHP using Go’s http.ResponseWriter
goroutines ➔ Goroutines are lightweight threads ➔ Goroutines are executed concurrently ➔ Goroutines can run in parallel on diﬀerent CPUs ➔ Go provides user-friendly synchronization mechanisms (channels) Goroutines
(system threads) and asynchronous I/O ➔ Several goroutines share the same OS thread ➔ Goroutines are lighter and faster than OS threads… ➔ …but ZTS isn’t enough to ensure PHP memory safety 😱 PHP must run in its own threads! Goroutines Aren’t OS Threads