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
380
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reactive PHP Events
Event loops in PHP.
Christopher Pitt
April 20, 2015
More Decks by Christopher Pitt
See All by Christopher Pitt
Making Robots (PHP Unicorn Conf)
chrispitt
1
240
Transforming Magento (NomadMage 2017)
chrispitt
2
140
Forget What You Know
chrispitt
1
180
Monads In PHP → php[tek]
chrispitt
3
570
Breaking The Enigma → php[tek]
chrispitt
0
260
Turn on the Generator!
chrispitt
0
190
Implementing Languages (FluentConf)
chrispitt
1
380
Async PHP (Sunshine)
chrispitt
0
520
Helpful Robot
chrispitt
0
160
Other Decks in Programming
See All in Programming
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.2k
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
220
スマートグラスで並列バイブコーディング
hyshu
0
120
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.3k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
520
Modding RubyKaigi for Myself
yui_knk
0
910
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
200
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.6k
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
250
Claspは野良GASの夢をみるか
takter00
0
180
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
660
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
200
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
310
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Building Adaptive Systems
keathley
44
3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Evolving SEO for Evolving Search Engines
ryanjones
0
210
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
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