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
250
Transforming Magento (NomadMage 2017)
chrispitt
2
140
Forget What You Know
chrispitt
1
180
Monads In PHP → php[tek]
chrispitt
3
580
Breaking The Enigma → php[tek]
chrispitt
0
270
Turn on the Generator!
chrispitt
0
200
Implementing Languages (FluentConf)
chrispitt
1
380
Async PHP (Sunshine)
chrispitt
0
530
Helpful Robot
chrispitt
0
180
Other Decks in Programming
See All in Programming
Building a Meta Ray-Ban display app
akkeylab
0
180
リアルな遅延を測る仕様
kota_yata
1
120
初めての模倣学習とVLA
natsutan
0
200
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
190
MySQLとPostgreSQLって何が違うの?
akagami
0
130
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
100
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2.1k
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
270
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
170
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
540
Cloudflare is Agents
chimame
0
180
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
290
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Google's AI Overviews - The New Search
badams
0
1.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
620
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
How to Ace a Technical Interview
jacobian
281
24k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
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