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
190
Transforming Magento (NomadMage 2017)
chrispitt
2
100
Forget What You Know
chrispitt
1
140
Monads In PHP → php[tek]
chrispitt
3
500
Breaking The Enigma → php[tek]
chrispitt
0
190
Turn on the Generator!
chrispitt
0
170
Implementing Languages (FluentConf)
chrispitt
1
340
Async PHP (Sunshine)
chrispitt
0
450
Helpful Robot
chrispitt
0
110
Other Decks in Programming
See All in Programming
コード書くの好きな人向けAIコーディング活用tips #orestudy
77web
3
250
がんばりすぎないコーディングルール運用術
tsukakei
1
210
Practical Tips and Tricks for Working with Compose Multiplatform Previews (mDevCamp 2025)
stewemetal
0
110
Zennの運営完全に理解した #完全に理解したTalk
wadayusuke
1
180
TypeScript を活かしてデザインシステム MCP を作る / #tskaigi_after_night
izumin5210
5
510
複数アプリケーションを育てていくための共通化戦略
irof
9
3.6k
Blueskyのプラグインを作ってみた
hakkadaikon
1
430
AIエージェントによるテストフレームワーク Arbigent
takahirom
0
350
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
3
1.9k
衛星の軌道をWeb地図上に表示する
sankichi92
0
260
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
1
140
セキュリティマネジャー廃止とクラウドネイティブ型サンドボックス活用
kazumura
1
150
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
770
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Thoughts on Productivity
jonyablonski
69
4.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
42
2.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.7k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.3k
A better future with KSS
kneath
239
17k
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