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
350
Async PHP (Sunshine)
chrispitt
0
460
Helpful Robot
chrispitt
0
110
Other Decks in Programming
See All in Programming
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
21k
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
15
5.4k
おやつのお供はお決まりですか?@WWDC25 Recap -Japan-\(region).swift
shingangan
0
140
Git Sync を超える!OSS で実現する CDK Pull 型デプロイ / Deploying CDK with PipeCD in Pull-style
tkikuc
4
310
Deep Dive into ~/.claude/projects
hiragram
14
12k
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
260
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
330
Agentic Coding: The Future of Software Development with Agents
mitsuhiko
0
120
NEWT Backend Evolution
xpromx
1
120
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
1k
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
710
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
210
Featured
See All Featured
Unsuck your backbone
ammeep
671
58k
Navigating Team Friction
lara
187
15k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
Music & Morning Musume
bryan
46
6.7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
Documentation Writing (for coders)
carmenintech
72
4.9k
We Have a Design System, Now What?
morganepeng
53
7.7k
Building Applications with DynamoDB
mza
95
6.5k
Optimizing for Happiness
mojombo
379
70k
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