HHVM’s Threading Difference – Not The Same as PHP-FPM

Profile image of Mattias Geniar

Mattias Geniar, April 06, 2015

Follow me on Twitter as @mattiasgeniar

I’m glad Etsy found this before the rest of us had to.

Most PHP SAPIs are implemented such that each request is handled by exactly one process, with many processes simultaneously handling many requests.

HHVM is a threaded SAPI. HHVM runs as a single process with multiple threads where each thread is only handling exactly one request. When you call setlocale(3) in this context it affects the locale for all threads in that process. As a result, requests can come in and trample the locales set by other requests as illustrated in this animation.

Code as Craft – Etsy blog

HHVM pays of. It’s more than twice as fast as PHP 5.4 in my benchmarks. But, it’s not a drop-in replacement for PHP-FPM.

As with everything: testing, testing & testing.

Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.