Slide 1

Slide 1 text

Reactive Events

Slide 2

Slide 2 text

You can do awesome things in PHP

Slide 3

Slide 3 text

$(".button").click(function() { $(".alert").show() .find(".label").html("You clicked a thing!"); });

Slide 4

Slide 4 text

var buttons = document.querySelectorAll(".button"); buttons.forEach(function(button) { button.addEventListener("click", function(event) { button.style.visibility = "visible"; var label = document.querySelector(".button .label"); label.innerHTML = "You clicked a thing!"; }); });

Slide 5

Slide 5 text

Questions?

Slide 6

Slide 6 text

This works because of the... event loop

Slide 7

Slide 7 text

And now for something completely different

Slide 8

Slide 8 text

This works because... Apache

Slide 9

Slide 9 text

And then mod_php takes over...

Slide 10

Slide 10 text

So, NodeJS then?

Slide 11

Slide 11 text

var http = require("http"); http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello World"); }) http.listen(1337, "127.0.0.1");

Slide 12

Slide 12 text

NodeJS takes on the roles of web server and request processor!

Slide 13

Slide 13 text

var filesystem = require("fs"); filesystem.readFile("/etc/passwd", function (error, data) { if (error) { throw err; } console.log(data); });

Slide 14

Slide 14 text

ReactPHP

Slide 15

Slide 15 text

Now we can do that NodeJS thing in PHP

Slide 16

Slide 16 text

PHP also has closures

Slide 17

Slide 17 text

Trouble is... NodeJS libraries are designed to be non-blocking

Slide 18

Slide 18 text

PHP is still mostly blocking

Slide 19

Slide 19 text

We can fix this in a few ways...

Slide 20

Slide 20 text

We can evolve PHP to have lots of non-blocking code in core

Slide 21

Slide 21 text

We can develop patterns and libraries for parallel execution

Slide 22

Slide 22 text

Asynchronous vs. Parallel Fight!

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

NodeJS is asynchronous but not parallel

Slide 27

Slide 27 text

WAT then?!

Slide 28

Slide 28 text

Queues

Slide 29

Slide 29 text

Queues are one-way

Slide 30

Slide 30 text

Queues are weak

Slide 31

Slide 31 text

GIEF STREGNTH!

Slide 32

Slide 32 text

https://github.com/asyncphp/remit

Slide 33

Slide 33 text

Starts with events...

Slide 34

Slide 34 text

then adds queues...

Slide 35

Slide 35 text

VoilĂ !

Slide 36

Slide 36 text

$server = new AsyncPHP\Remit\Adapter\ZeroMQ\Server( // some boring guff ); $server->addListener("tick", function ($event, $i) { print "TICK {$i}\n"; }); $server->addListener("done", function ($event) { print "DONE\n"; }); $loop->run();

Slide 37

Slide 37 text

$client = new AsyncPHP\Remit\Adapter\ZeroMQ\Client( // some more boring guff ); foreach (range(1, 5) as $i) { $loop->addTimer($i, function () use ($client, $i) { $client->emit("tick", $i); }); } $loop->addTimer(6, function () use ($client) { $client->emit("done"); }); $loop->run();

Slide 38

Slide 38 text

Distributed, non-blocking events for bi-directional communication with message queue workers

Slide 39

Slide 39 text

Reactive PHP events