Asynchronous PHP

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 07, 2014

Follow me on Twitter as @mattiasgeniar

A really cool feature landed in HHVM, providing async PHP calls.

While your https call is busy sitting on its hands waiting for a response, there’s no reason you shouldn’t be able to do other things, maybe even fire off more requests. The same goes for database queries, which can take just as long, or even filesystem access which is faster than network, but can still introduce lag times of several milliseconds, and those all add up!

But, HHVM isn’t PHP. And PHP has no such feature yet, but it may come to PHP7 when PHP’s IO multiplexing is revamped. So for now, we’re left with workarounds like ReactPHP, background forking of requests, curl_multi_exec() shenanigans and running worker-queues like Gearman.

Sure it gets the job done, but native async looks pretty damn cool.



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.