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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Christopher Pitt
April 20, 2015
Programming
370
1
Share
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
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
260
Turn on the Generator!
chrispitt
0
190
Implementing Languages (FluentConf)
chrispitt
1
370
Async PHP (Sunshine)
chrispitt
0
510
Helpful Robot
chrispitt
0
150
Other Decks in Programming
See All in Programming
10 Tips of AWS ~Gen AI on AWS~
licux
5
400
AI-DLC Deep Dive
yuukiyo
9
4.2k
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
190
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.4k
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
780
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
500
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
Kingdom of the Machine
yui_knk
2
320
第3木曜LT会 #28
tinykitten
PRO
0
110
一度始めたらやめられない開発効率向上術 / Findy あなたのdotfilesを教えて!
k0kubun
4
3k
実践CRDT
tamadeveloper
0
570
アーキテクチャモダナイゼーションとは何か
nwiizo
19
5.2k
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
730
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
27
3.4k
The Spectacular Lies of Maps
axbom
PRO
1
700
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
Ethics towards AI in product and experience design
skipperchong
2
260
Everyday Curiosity
cassininazir
0
200
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
190
Odyssey Design
rkendrick25
PRO
2
570
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.5k
BBQ
matthewcrist
89
10k
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