Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
390
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
Transcript
39 slides
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
More Decks by Christopher Pitt
See All by Christopher Pitt
Making Robots (PHP Unicorn Conf)
chrispitt
1
260
Transforming Magento (NomadMage 2017)
chrispitt
2
150
Forget What You Know
chrispitt
1
210
Monads In PHP → php[tek]
chrispitt
3
600
Breaking The Enigma → php[tek]
chrispitt
0
300
Turn on the Generator!
chrispitt
0
210
Implementing Languages (FluentConf)
chrispitt
1
400
Async PHP (Sunshine)
chrispitt
0
550
Helpful Robot
chrispitt
0
190
Other Decks in Programming
See All in Programming
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
580
ruby/uri meets WHATWG
jinroq
0
190
Lean で手続き的プログラム の証明が書けるようになった
inoueasei
11
5.8k
LambdaなのにVM?Lambda MicroVMsを調べてみた / About Lambda Micro VMs
ak2ie
2
110
正解の無い問題を 「できるだけ上手く」解く ヒューリスティックで感性を磨こう。〜現実課題をプログラミングで解きあうコミュニティについて〜
allegrogiken
0
120
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
210
Spec-driven Development with AI
simas
PRO
0
2.3k
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
250
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
350
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
680
祈るテストから、探索するテストへ 〜Lincheckではじめる並行処理テスト〜
yyh_gl
0
440
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
1k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
550
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.5k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.7k
HDC tutorial
michielstock
2
1k
Thoughts on Productivity
jonyablonski
76
5.5k
Site-Speed That Sticks
csswizardry
13
1.6k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
500
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Unsuck your backbone
ammeep
672
58k
30 Presentation Tips
portentint
PRO
1
480