Subscribe to PHP Freaks RSS

Tideways.io: Using php-fpm as a simple built-in async queue

syndicated from www.phpdeveloper.org on August 21, 2017

On the Tideways blog Benjamin Eberlei has written up a post showing how to use php-fpm as a "poor man's queue" system, making it easier to hand off requests to be worked on out of band without having to install other software.

There are many tasks that a web-request should not perform directly so the user doesn't have to wait many seconds for a response. [...] The usual advice you find on the internet is to setup a queue such as RabbitMQ, Redis, Kafka, Gearman or Beanstalkd. But this means another service that you need to install, setup, maintain and monitor. With some of the queue systems operating them includes a steep learning phase that requires time and money for additional hardware.

But maybe you just need a poor mans version of an asynchronous queue without all the overhead? Then why not just use PHP-FPM itself?

He admits that it's more of an "experimental approach" but feels like it could be a viable option for the php-fpm users out there. He then shows how to use the hollodotme/fast-cgi-client library to execute an asynchronous request for a "SendEmail" command. The request is then passed off to another PHP-FPM worker for processing without the user having to wait on a result. He ends the post with a few words of warning about using this approach and some other methods for getting around the offloading of longer processing.