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
150
Transforming Magento (NomadMage 2017)
chrispitt
2
85
Forget What You Know
chrispitt
1
130
Monads In PHP → php[tek]
chrispitt
3
470
Breaking The Enigma → php[tek]
chrispitt
0
160
Turn on the Generator!
chrispitt
0
150
Implementing Languages (FluentConf)
chrispitt
1
310
Async PHP (Sunshine)
chrispitt
0
420
Helpful Robot
chrispitt
0
97
Other Decks in Programming
See All in Programming
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
230
traP の部内 ISUCON とそれを支えるポータル / PISCON Portal
ikura_hamu
0
180
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.4k
Оптимизируем производительность блока Казначейство
lamodatech
0
950
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.8k
令和7年版 あなたが使ってよいフロントエンド機能とは
mugi_uno
10
5.1k
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
240
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
940
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
150
php-conference-japan-2024
tasuku43
0
430
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
700
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
170
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
The Pragmatic Product Professional
lauravandoore
32
6.4k
Building Applications with DynamoDB
mza
93
6.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
Writing Fast Ruby
sferik
628
61k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
113
50k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
240
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
3
180
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