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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Christopher Pitt
April 20, 2015
Programming
1
370
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
230
Transforming Magento (NomadMage 2017)
chrispitt
2
130
Forget What You Know
chrispitt
1
170
Monads In PHP → php[tek]
chrispitt
3
560
Breaking The Enigma → php[tek]
chrispitt
0
250
Turn on the Generator!
chrispitt
0
180
Implementing Languages (FluentConf)
chrispitt
1
370
Async PHP (Sunshine)
chrispitt
0
500
Helpful Robot
chrispitt
0
150
Other Decks in Programming
See All in Programming
2026-03-27 #terminalnight 変数展開とコマンド展開でターミナル作業をスマートにする方法
masasuzu
0
150
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
440
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
500
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
230
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.1k
Windows on Ryzen and I
seosoft
0
390
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
330
SourceGeneratorのマーカー属性問題について
htkym
0
220
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
270
Vuetify 3 → 4 何が変わった?差分と移行ポイント10分まとめ
koukimiura
0
190
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
230
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
3
1.9k
Featured
See All Featured
How to Talk to Developers About Accessibility
jct
2
160
Google's AI Overviews - The New Search
badams
0
950
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
230
What does AI have to do with Human Rights?
axbom
PRO
1
2.1k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
420
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
110
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
Ruling the World: When Life Gets Gamed
codingconduct
0
180
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
490
How to make the Groovebox
asonas
2
2k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
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