Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive PHP Events

Reactive PHP Events

Event loops in PHP.

Christopher Pitt

April 20, 2015
Tweet

More Decks by Christopher Pitt

Other Decks in Programming

Transcript

  1. 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!"; }); });
  2. 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");
  3. $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();
  4. $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();