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
210
Transforming Magento (NomadMage 2017)
chrispitt
2
110
Forget What You Know
chrispitt
1
150
Monads In PHP → php[tek]
chrispitt
3
520
Breaking The Enigma → php[tek]
chrispitt
0
210
Turn on the Generator!
chrispitt
0
170
Implementing Languages (FluentConf)
chrispitt
1
350
Async PHP (Sunshine)
chrispitt
0
470
Helpful Robot
chrispitt
0
120
Other Decks in Programming
See All in Programming
Pythonに漸進的に型をつける
nealle
1
130
理論と実務のギャップを超える
eycjur
0
180
Webサーバーサイド言語としてのRustについて
kouyuume
1
4.9k
なんでRustの環境構築してないのにRust製のツールが動くの? / Why Do Rust-Based Tools Run Without a Rust Environment?
ssssota
14
46k
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
34k
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
380
はじめてのDSPy - 言語モデルを『プロンプト』ではなく『プログラミング』するための仕組み
masahiro_nishimi
4
16k
Six and a half ridiculous things to do with Quarkus
hollycummins
0
220
AI駆動で0→1をやって見えた光と伸びしろ
passion0102
1
860
Reactive Thinking with Signals and the Resource API
manfredsteyer
PRO
0
110
Claude CodeによるAI駆動開発の実践 〜そこから見えてきたこれからのプログラミング〜
iriikeita
0
360
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
510
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
Speed Design
sergeychernyshev
32
1.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Designing for humans not robots
tammielis
254
26k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
620
Git: the NoSQL Database
bkeepers
PRO
431
66k
Into the Great Unknown - MozCon
thekraken
40
2.1k
Keith and Marios Guide to Fast Websites
keithpitt
411
23k
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