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
360
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
550
Breaking The Enigma → php[tek]
chrispitt
0
240
Turn on the Generator!
chrispitt
0
180
Implementing Languages (FluentConf)
chrispitt
1
360
Async PHP (Sunshine)
chrispitt
0
500
Helpful Robot
chrispitt
0
150
Other Decks in Programming
See All in Programming
CSC307 Lecture 08
javiergs
PRO
0
690
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
440
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
130
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1.1k
ぼくの開発環境2026
yuzneri
1
290
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
460
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
260
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
300
浮動小数の比較について
kishikawakatsumi
0
340
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
2
940
Railsの気持ちを考えながらコントローラとビューを整頓する/tidying-rails-controllers-and-views-as-rails-think
moro
4
340
ふん…おもしれぇ Parser。RubyKaigi 行ってやるぜ
aki_pin0
0
110
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
Chasing Engaging Ingredients in Design
codingconduct
0
120
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
180
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
Abbi's Birthday
coloredviolet
2
5k
How to build a perfect <img>
jonoalderson
1
5.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Utilizing Notion as your number one productivity tool
mfonobong
3
230
Automating Front-end Workflow
addyosmani
1371
200k
Documentation Writing (for coders)
carmenintech
77
5.3k
Test your architecture with Archunit
thirion
1
2.2k
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