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
370
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
230
Transforming Magento (NomadMage 2017)
chrispitt
2
130
Forget What You Know
chrispitt
1
170
Monads In PHP → php[tek]
chrispitt
3
550
Breaking The Enigma → php[tek]
chrispitt
0
250
Turn on the Generator!
chrispitt
0
180
Implementing Languages (FluentConf)
chrispitt
1
370
Async PHP (Sunshine)
chrispitt
0
500
Helpful Robot
chrispitt
0
150
Other Decks in Programming
See All in Programming
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
160
技術検証結果の整理と解析をAIに任せよう!
keisukeikeda
0
120
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
260
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
2
370
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.4k
[SF Ruby Feb'26] The Silicon Heel
palkan
0
110
TipKitTips
ktcryomm
0
170
受け入れテスト駆動開発(ATDD)×AI駆動開発 AI時代のATDDの取り組み方を考える
kztakasaki
2
590
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
200
CSC307 Lecture 14
javiergs
PRO
0
470
Docコメントで始める簡単ガードレール
keisukeikeda
1
120
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
150
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
Automating Front-end Workflow
addyosmani
1370
200k
It's Worth the Effort
3n
188
29k
4 Signs Your Business is Dying
shpigford
187
22k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
200
Java REST API Framework Comparison - PWX 2021
mraible
34
9.2k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.7k
Into the Great Unknown - MozCon
thekraken
40
2.3k
Color Theory Basics | Prateek | Gurzu
gurzu
0
250
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