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.

This talk was recently given as PHP Multitasking Without Forking at LinuxFest Northwest 2012 and the topic is further described by cotto in the High Performance group at http://groups.drupal.org/node/226054

Video: http://blip.tv/ladrupal/episode/6128019  
Comments: http://groups.drupal.org/node/223324#comments