Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
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
210
Transforming Magento (NomadMage 2017)
chrispitt
2
120
Forget What You Know
chrispitt
1
160
Monads In PHP → php[tek]
chrispitt
3
530
Breaking The Enigma → php[tek]
chrispitt
0
220
Turn on the Generator!
chrispitt
0
180
Implementing Languages (FluentConf)
chrispitt
1
360
Async PHP (Sunshine)
chrispitt
0
480
Helpful Robot
chrispitt
0
140
Other Decks in Programming
See All in Programming
クラウドに依存しないS3を使った開発術
simesaba80
0
150
AIコーディングエージェント(NotebookLM)
kondai24
0
220
Cell-Based Architecture
larchanjo
0
140
Python札幌 LT資料
t3tra
6
1k
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
130
Implementation Patterns
denyspoltorak
0
110
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
130
Go コードベースの構成と AI コンテキスト定義
andpad
0
140
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
230
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
180
AIエージェントの設計で注意するべきポイント6選
har1101
5
2.1k
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.3k
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
870
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
250
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The SEO identity crisis: Don't let AI make you average
varn
0
36
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
69
The Mindset for Success: Future Career Progression
greggifford
PRO
0
190
Designing Powerful Visuals for Engaging Learning
tmiket
0
190
Context Engineering - Making Every Token Count
addyosmani
9
550
Why Our Code Smells
bkeepers
PRO
340
57k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
73
What the history of the web can teach us about the future of AI
inesmontani
PRO
0
370
Balancing Empowerment & Direction
lara
5
820
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