Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
590
Breaking The Enigma → php[tek]
chrispitt
0
280
Turn on the Generator!
chrispitt
0
200
Implementing Languages (FluentConf)
chrispitt
1
390
Async PHP (Sunshine)
chrispitt
0
540
Helpful Robot
chrispitt
0
180
Other Decks in Programming
See All in Programming
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
390
Simple Storage Service(S3) is not simple
iwatsukayura
0
120
Java 27新機能 / Java 27 new features
kishida
2
190
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.7k
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
1k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
290
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
290
カツオ、ご期待ください
suneo3476
0
130
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
110
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
570
App Intentsのビルドプロセスを支える技術
kntkymt
0
490
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
510
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
Building AI with AI
inesmontani
PRO
1
1.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
700
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
A Tale of Four Properties
chriscoyier
163
24k
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