Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Reactive PHP Events
Search
Christopher Pitt
April 20, 2015
Programming
1
350
Reactive PHP Events
Event loops in PHP.
Christopher Pitt
April 20, 2015
Tweet
Share
More Decks by Christopher Pitt
See All by Christopher Pitt
Making Robots (PHP Unicorn Conf)
chrispitt
1
160
Transforming Magento (NomadMage 2017)
chrispitt
2
88
Forget What You Know
chrispitt
1
130
Monads In PHP → php[tek]
chrispitt
3
480
Breaking The Enigma → php[tek]
chrispitt
0
170
Turn on the Generator!
chrispitt
0
150
Implementing Languages (FluentConf)
chrispitt
1
320
Async PHP (Sunshine)
chrispitt
0
430
Helpful Robot
chrispitt
0
100
Other Decks in Programming
See All in Programming
AWS Step Functions は CDK で書こう!
konokenj
4
540
未経験でSRE、はじめました! 組織を支える役割と軌跡
curekoshimizu
1
170
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
200
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
930
「個人開発マネタイズ大全」が教えてくれたこと
bani24884
1
260
Honoとフロントエンドの 型安全性について
yodaka
7
1.5k
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
1.1k
Jakarta EE meets AI
ivargrimstad
0
470
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
250
Domain-Driven Design (Tutorial)
hschwentner
13
22k
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
7
4.2k
Jakarta EE meets AI
ivargrimstad
0
510
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.2k
Documentation Writing (for coders)
carmenintech
67
4.6k
A better future with KSS
kneath
238
17k
How to Ace a Technical Interview
jacobian
276
23k
Designing for Performance
lara
604
68k
Bash Introduction
62gerente
611
210k
Designing Experiences People Love
moore
140
23k
Embracing the Ebb and Flow
colly
84
4.6k
Mobile First: as difficult as doing things right
swwweet
223
9.5k
Navigating Team Friction
lara
183
15k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Transcript
Reactive Events
You can do awesome things in PHP
$(".button").click(function() { $(".alert").show() .find(".label").html("You clicked a thing!"); });
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!"; }); });
Questions?
This works because of the... event loop
And now for something completely different
This works because... Apache
And then mod_php takes over...
So, NodeJS then?
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");
NodeJS takes on the roles of web server and request
processor!
var filesystem = require("fs"); filesystem.readFile("/etc/passwd", function (error, data) { if
(error) { throw err; } console.log(data); });
ReactPHP
Now we can do that NodeJS thing in PHP
PHP also has closures
Trouble is... NodeJS libraries are designed to be non-blocking
PHP is still mostly blocking
We can fix this in a few ways...
We can evolve PHP to have lots of non-blocking code
in core
We can develop patterns and libraries for parallel execution
Asynchronous vs. Parallel Fight!
None
None
None
NodeJS is asynchronous but not parallel
WAT then?!
Queues
Queues are one-way
Queues are weak
GIEF STREGNTH!
https://github.com/asyncphp/remit
Starts with events...
then adds queues...
Voilà!
$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();
$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();
Distributed, non-blocking events for bi-directional communication with message queue workers
Reactive PHP events