HTTPRL

Using HTTPRL for Parallelization: PHP Multitasking Without Forking With stream_select()

  • Posted on: 12 May 2012
  • By: Christefano Reyes

Did you know that PHP comes with a very powerful function called stream_select()? In short it's a wrapper for the select() system call. This allows for synchronous I/O multiplexing, or in sudo-code, a way to read multiple input/output streams without blocking; only selecting streams that are ready for I/O. In English this means that you can do parallel work from a single PHP thread without forking (forking a process is slow and complex in PHP).

In this talk at the High Performance Drupal meetup at Droplabs on May 1, 2012, Mike Carper (@mcarper) went over some code called the HTTP Parallel Request & Threading Library — or HTTPRL in short. Using PHP's stream_select() HTTPRL can send http requests out in parallel. These requests can be made in a blocking or non-blocking way. Blocking will wait for the HTTP response; Non-Blocking will close the connection not waiting for the response back. Non-Blocking requests are what make this better in comparison to cURL, better control over redirects is the other reason.