Non-blocking IO

Using the RxPHP extensions opens up quite a few possibilities. Its observables, operators, and subscribers/observers implementations are certainly powerful. What they don't provide, however, is asynchronicity. This is where the React library comes into play, by providing an event-driven, non-blocking I/O abstraction layer. Before we touch upon React, let's first lay out a trivial example of blocking versus non-blocking I/O in PHP.

We create a small beacon script that will merely generate some standard output (stdout) over time. Then, we will create a script that reads from the standard input (stdin) and see how it behaves when reading is done in the stream blocking and stream non-blocking mode.

We start by creating the beacon.php ...

Get Mastering PHP 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.