Jonathan VUILLEMIN
PHP, Go, mostly.
Jonathan VUILLEMIN
2017-02
To put it simply, it is a matter of listening to events from multiple sources to react to them asynchronously.
The result produced by the application, for example an html page, is not constructed by following a procedure in a well defined order, but by reacting to the different types of events that can influence this result.
It is particularly suitable when the application is often waiting for external calls (database, REST API),
or actions of a user (click on a button, message in a chat).
To read: http://www.reactivemanifesto.org/en
The reactor design pattern is an event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs.
The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated event handler.
ReactPHP event loop = single thread
Paralleling external calls (for non-blocking IO):
Let a php script run as an http or socket server:
Blocking I/O download (regular_download.php)
Downloading file node-v0.6.18.tar.gz ... download OK, size : 9.786 MB
Downloading file php-5.5.15.tar.gz ... download OK, size : 16.301 MB
Downloading file node-v0.11.9-sunos-x64.tar.gz ... download OK, size : 6.954 MB
Downloading file node-v0.11.9-sunos-x86.tar.gz ... download OK, size : 6.567 MB
Execution time: 12.392359972%
Parallel react loop download (parallel_download.php)
##### Loop tick #####
node-v0.6.18.tar.gz: 1.311 MB
php-5.5.15.tar.gz: 1.911 MB
node-v0.11.9-sunos-x64.tar.gz: 2.382 MB
node-v0.11.9-sunos-x86.tar.gz: 0.610 MB
##### Loop tick #####
node-v0.6.18.tar.gz: 2.606 MB
php-5.5.15.tar.gz: 3.402 MB
node-v0.11.9-sunos-x64.tar.gz: 5.606 MB
node-v0.11.9-sunos-x86.tar.gz: 1.492 MB
Finished downloading node-v0.11.9-sunos-x64.tar.gz
##### Loop tick #####
node-v0.6.18.tar.gz: 4.486 MB
php-5.5.15.tar.gz: 4.949 MB
node-v0.11.9-sunos-x86.tar.gz: 2.759 MB
##### Loop tick #####
node-v0.6.18.tar.gz: 7.001 MB
php-5.5.15.tar.gz: 7.542 MB
node-v0.11.9-sunos-x86.tar.gz: 4.337 MB
##### Loop tick #####
node-v0.6.18.tar.gz: 9.681 MB
php-5.5.15.tar.gz: 10.152 MB
node-v0.11.9-sunos-x86.tar.gz: 5.296 MB
Finished downloading node-v0.6.18.tar.gz
Finished downloading node-v0.11.9-sunos-x86.tar.gz
##### Loop tick #####
php-5.5.15.tar.gz: 13.643 MB
Finished downloading php-5.5.15.tar.gz
##### Loop tick #####
Execution time: 7.9870839118958%
Ratchet: WebSockets for PHP, based on ReactPHP
Ratchet is a loosely coupled PHP library providing developers with tools to create real time,
bi-directional applications between clients and servers over WebSockets.
This is not your Grandfather's Internet.
Doc: http://socketo.me/
Example: server.php
Thanks !
By Jonathan VUILLEMIN
Reactive programming with PHP