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
1
350
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
140
Transforming Magento (NomadMage 2017)
chrispitt
2
78
Forget What You Know
chrispitt
1
120
Monads In PHP → php[tek]
chrispitt
3
450
Breaking The Enigma → php[tek]
chrispitt
0
140
Turn on the Generator!
chrispitt
0
150
Implementing Languages (FluentConf)
chrispitt
1
300
Async PHP (Sunshine)
chrispitt
0
400
Helpful Robot
chrispitt
0
94
Other Decks in Programming
See All in Programming
hotwire_or_react
harunatsujita
8
4.1k
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
250
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
qmuntal/stateless のススメ
sgash708
0
120
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
CSC305 Lecture 13
javiergs
PRO
0
130
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.4k
Java ジェネリクス入門 2024
nagise
0
600
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
Featured
See All Featured
Ruby is Unlike a Banana
tanoku
96
11k
Gamification - CAS2011
davidbonilla
80
5k
The Language of Interfaces
destraynor
154
24k
Designing the Hi-DPI Web
ddemaree
280
34k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building Your Own Lightsaber
phodgson
102
6k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
What's new in Ruby 2.0
geeforr
342
31k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
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