Preface
Reactive programming has gained distinct popularity in recent years. This is partly thanks to JavaScript web frameworks such as Angular2 or React, but also because of the increasing popularity of functional and asynchronous programming in languages that support multiple programming paradigms, such as JavaScript, Java, Python, or PHP.
Nowadays, reactive programming is closely associated with Reactive Extensions (also called ReactiveX or just Rx); the most popular library to leverage reactive programming. Notably, RxJS 5, the JavaScript implementation of Rx, is very likely to be the first encounter with reactive programming for many developers. In this book, we will mostly focus on using the PHP port of Rx, called RxPHP (https://github.com/ReactiveX/RxPHP).
Asynchronous programming is not what PHP developers typically deal with. In fact, it’s kind of an uncharted territory because there aren’t many resources available on this topic in PHP. Since reactive programming goes hand in hand with asynchronous programming, we’ll work a lot with event loops, blocking and non-blocking code, subprocesses, threads, and IPC.
Our primary intention, however, will be learning Reactive Extensions and reactive programming with RxPHP. This book includes both RxPHP 1 and RxPHP 2. All examples are written for RxPHP 1 because the API is almost the same, and at the time of writing this book, RxPHP 2 is still in development. Also, RxPHP 1 requires just PHP 5.6+, while RxPHP 2 requires PHP 7+. Nonetheless, we’ll properly emphasize and explain whenever the APIs of RxPHP 1 and RxPHP 2 differ.