SlideShare a Scribd company logo
Reactive Programming
in PHP
Johney Park
2018.06.17
Reactive Programming
=
Observer Pattern
+ LINQ-style operators
( + Schedulers)
TL; DR
Pros:
Good for handling async events
Cons:
Difficult to understand
Too many things to learn
Some overhead
TL; DR
Definition
Reactive Programming is
programming with
asynchronous
data streams.
https://gist.github.com/
staltz/868e7e9bc2a7b8c1f754
(Where is reactive?)
What you heard when you
learn reactive programming
• Observer/Observable / Hot & Cold
• Signal / Flux / Stream / EventStream / EventSource / …
• Subject
• Scheduler
• Publish / Subscribe / Unsubscribe / Dispose / Behavior
• Producer / Consumer
• Map / Reduce / Throttle / …
Observer Pattern
Observer 1
Observable
watch & run
Observer 2
♨
(Event Source)
wrap
Observer Pattern
Observer 1
Observable
subscribe
Lazy Evaluation
Subscription 1
async call with
stream operators
Observer 2 Subscription 2
Observers don’t observe
Observable does all the work
Producer / Consumer may be better naming
Observer Pattern
Observer 1
Observable 1
Observer 2
Observer 3
Subject 1
Subject 2
Subject = Observable + Observer
broadcast
♨
(Event Source)
♨
(Event Source)
direct call
When to use RP?
• One or more event sources
• Require stream operators
• Not a perfect solution for all
async scenarios
• External API Call (MSA)
• UI Events (Click)
• Message Processing
• Abstraction over Async Process
RxPHP
• stream_select (PHP 4 >= 4.3.0, PHP 5, PHP 7)
• ReactPHP != RxPHP
• ReactPHP is event-driven, non-blocking I/O library
• EventLoop, Promise from ReactPHP
• https://github.com/ReactiveX/RxPHP
RxPHP
$source = RxObservable ::fromArray([1, 2, 3, 4]);
$observer = new RxObserverCallbackObserver(
function ($x) {
echo 'Next: ', $x, PHP_EOL;
},
function (Exception $ex) {
echo 'Error: ', $ex ->getMessage(), PHP_EOL;
},
function () {
echo 'Completed', PHP_EOL;
});
$source ->subscribe($observer);
// Next: 1
// Next: 2
// Next: 3
// Next: 4
// Completed
Very simple sample code
• Cold Observable Sample, almost
useless
• Source = Observable
• Subscribe Observer to
Observable
• Observer is consist of three
functions
• next, error, completed
RxPHP
$loop = Factory ::create();
Scheduler ::setDefaultFactory(function () use ($loop) {
return new SchedulerEventLoopScheduler($loop);
});
register_shutdown_function(function () use ($loop) {
$loop ->run();
});
Observable ::interval(1000)
->take(5)
->flatMap(function ($i) {
return Observable ::of($i + 1);
})
->subscribe(function ($e) {
echo $e, PHP_EOL;
});
// 1
// 2
// 3
// 4
// 5
Event Loop
• We need to set EventLoop when using
stream operator
• interval, throttle, etc..
• If you don’t use stream operator, you
don’t need to set EventLoop
• RxJs don’t require explicit event loop,
because Javascript has setTimeout,
setInterval, requestAnimationFrame
• There are many scheduler types
• flatMap == mergeMap, but RxPHP don’t
provide mergeMap
RxPHP
$subject = new RxSubjectSubject();
$subject ->subscribe(function($i) { echo $i . PHP_EOL;});
RxObservable ::interval(1000)
->take(5)
->flatMap(function ($i) {
return Observable ::of($i + 1);
})
->subscribe($subject);
$subject ->onNext(10);
$subject ->onNext(20);
$subject ->onNext(30);
// 10
// 20
// 30
// 1
// 2
// 3
// 4
// 5
Subject
• Subject = Observable +
Observer
• Actually Subject is extended
from Observable
• You don’t need to create custom
Observable for simple usage
RxPHP
More Samples
• https://github.com/ReactiveX/RxPHP/tree/master/demo
• https://github.com/PacktPublishing/PHP-Reactive-
Programming/
• https://www.packtpub.com/web-development/php-
reactive-programming
RxPHP
Ben Lesh’s comment
RxJS could be so simple... just a handful of types and operators.
... but if we do that, then people shoot themselves in the foot with memory
leaks and their own poorly implemented `expand` operator or whatever… ...
so then we add 60+ operators and people are like "WHOA...." haha.. Now it's
too complicated.
It's tough everywhere. Haha
If I had a nickel for every poorly implemented custom RxJS operator I've
seen… ... I'd only have about 25 cents, because we've already built almost
every tool someone could want.
But who have we scared off in the process?
The End
Ad

More Related Content

Similar to Reactive programming in PHP (20)

Introduction to reactive programming
Introduction to reactive programmingIntroduction to reactive programming
Introduction to reactive programming
Leapfrog Technology Inc.
 
RxJava@Android
RxJava@AndroidRxJava@Android
RxJava@Android
Maxim Volgin
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander
 
ReactPHP
ReactPHPReactPHP
ReactPHP
Philip Norton
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
PROIDEA
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
King Foo
 
FailureEnrichers - Flink Meetup Bay Area.pptx
FailureEnrichers - Flink Meetup Bay Area.pptxFailureEnrichers - Flink Meetup Bay Area.pptx
FailureEnrichers - Flink Meetup Bay Area.pptx
Panagiotis Garefalakis
 
Reactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETReactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NET
EPAM
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
PyData
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside Out
Ferenc Kovács
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy
Fwdays
 
Node.js primer
Node.js primerNode.js primer
Node.js primer
Quhan Arunasalam
 
JDK8 Streams
JDK8 StreamsJDK8 Streams
JDK8 Streams
Bansilal Haudakari
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & Akka
Yardena Meymann
 
Airflow 101
Airflow 101Airflow 101
Airflow 101
SaarBergerbest
 
Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2
ppd1961
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
YarikS
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
Adam Englander
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
PROIDEA
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
King Foo
 
FailureEnrichers - Flink Meetup Bay Area.pptx
FailureEnrichers - Flink Meetup Bay Area.pptxFailureEnrichers - Flink Meetup Bay Area.pptx
FailureEnrichers - Flink Meetup Bay Area.pptx
Panagiotis Garefalakis
 
Reactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NETReactive Extensions: classic Observer in .NET
Reactive Extensions: classic Observer in .NET
EPAM
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
PyData
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside Out
Ferenc Kovács
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy
Fwdays
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & Akka
Yardena Meymann
 
Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2Handling Exceptions In C & C++ [Part B] Ver 2
Handling Exceptions In C & C++ [Part B] Ver 2
ppd1961
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
YarikS
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
Adam Englander
 

Recently uploaded (20)

Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
Compiler Design_Code generation techniques.pptx
Compiler Design_Code generation techniques.pptxCompiler Design_Code generation techniques.pptx
Compiler Design_Code generation techniques.pptx
RushaliDeshmukh2
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
MODULE 03 - CLOUD COMPUTING- [BIS 613D] 2022 scheme.pptx
MODULE 03 - CLOUD COMPUTING-  [BIS 613D] 2022 scheme.pptxMODULE 03 - CLOUD COMPUTING-  [BIS 613D] 2022 scheme.pptx
MODULE 03 - CLOUD COMPUTING- [BIS 613D] 2022 scheme.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Compiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptxCompiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptx
RushaliDeshmukh2
 
2025 Apply BTech CEC .docx
2025 Apply BTech CEC                 .docx2025 Apply BTech CEC                 .docx
2025 Apply BTech CEC .docx
tusharmanagementquot
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Analog electronic circuits with some imp
Analog electronic circuits with some impAnalog electronic circuits with some imp
Analog electronic circuits with some imp
KarthikTG7
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Comprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptxComprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptx
dd7devdilip
 
Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Journal of Soft Computing in Civil Engineering
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Compiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptxCompiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptx
RushaliDeshmukh2
 
NOMA analysis in 5G communication systems
NOMA analysis in 5G communication systemsNOMA analysis in 5G communication systems
NOMA analysis in 5G communication systems
waleedali330654
 
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdf
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdfCOMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdf
COMPUTER GRAPHICS AND VISUALIZATION :MODULE-02 notes [BCG402-CG&V].pdf
Alvas Institute of Engineering and technology, Moodabidri
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
Compiler Design_Code generation techniques.pptx
Compiler Design_Code generation techniques.pptxCompiler Design_Code generation techniques.pptx
Compiler Design_Code generation techniques.pptx
RushaliDeshmukh2
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
Compiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptxCompiler Design_Code Optimization tech.pptx
Compiler Design_Code Optimization tech.pptx
RushaliDeshmukh2
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Analog electronic circuits with some imp
Analog electronic circuits with some impAnalog electronic circuits with some imp
Analog electronic circuits with some imp
KarthikTG7
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Comprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptxComprehensive-Event-Management-System.pptx
Comprehensive-Event-Management-System.pptx
dd7devdilip
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Compiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptxCompiler Design_Intermediate code generation new ppt.pptx
Compiler Design_Intermediate code generation new ppt.pptx
RushaliDeshmukh2
 
NOMA analysis in 5G communication systems
NOMA analysis in 5G communication systemsNOMA analysis in 5G communication systems
NOMA analysis in 5G communication systems
waleedali330654
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Ad

Reactive programming in PHP

  • 2. Reactive Programming = Observer Pattern + LINQ-style operators ( + Schedulers) TL; DR
  • 3. Pros: Good for handling async events Cons: Difficult to understand Too many things to learn Some overhead TL; DR
  • 4. Definition Reactive Programming is programming with asynchronous data streams. https://gist.github.com/ staltz/868e7e9bc2a7b8c1f754 (Where is reactive?)
  • 5. What you heard when you learn reactive programming • Observer/Observable / Hot & Cold • Signal / Flux / Stream / EventStream / EventSource / … • Subject • Scheduler • Publish / Subscribe / Unsubscribe / Dispose / Behavior • Producer / Consumer • Map / Reduce / Throttle / …
  • 6. Observer Pattern Observer 1 Observable watch & run Observer 2 ♨ (Event Source) wrap
  • 7. Observer Pattern Observer 1 Observable subscribe Lazy Evaluation Subscription 1 async call with stream operators Observer 2 Subscription 2 Observers don’t observe Observable does all the work Producer / Consumer may be better naming
  • 8. Observer Pattern Observer 1 Observable 1 Observer 2 Observer 3 Subject 1 Subject 2 Subject = Observable + Observer broadcast ♨ (Event Source) ♨ (Event Source) direct call
  • 9. When to use RP? • One or more event sources • Require stream operators • Not a perfect solution for all async scenarios • External API Call (MSA) • UI Events (Click) • Message Processing • Abstraction over Async Process
  • 10. RxPHP • stream_select (PHP 4 >= 4.3.0, PHP 5, PHP 7) • ReactPHP != RxPHP • ReactPHP is event-driven, non-blocking I/O library • EventLoop, Promise from ReactPHP • https://github.com/ReactiveX/RxPHP
  • 11. RxPHP $source = RxObservable ::fromArray([1, 2, 3, 4]); $observer = new RxObserverCallbackObserver( function ($x) { echo 'Next: ', $x, PHP_EOL; }, function (Exception $ex) { echo 'Error: ', $ex ->getMessage(), PHP_EOL; }, function () { echo 'Completed', PHP_EOL; }); $source ->subscribe($observer); // Next: 1 // Next: 2 // Next: 3 // Next: 4 // Completed Very simple sample code • Cold Observable Sample, almost useless • Source = Observable • Subscribe Observer to Observable • Observer is consist of three functions • next, error, completed
  • 12. RxPHP $loop = Factory ::create(); Scheduler ::setDefaultFactory(function () use ($loop) { return new SchedulerEventLoopScheduler($loop); }); register_shutdown_function(function () use ($loop) { $loop ->run(); }); Observable ::interval(1000) ->take(5) ->flatMap(function ($i) { return Observable ::of($i + 1); }) ->subscribe(function ($e) { echo $e, PHP_EOL; }); // 1 // 2 // 3 // 4 // 5 Event Loop • We need to set EventLoop when using stream operator • interval, throttle, etc.. • If you don’t use stream operator, you don’t need to set EventLoop • RxJs don’t require explicit event loop, because Javascript has setTimeout, setInterval, requestAnimationFrame • There are many scheduler types • flatMap == mergeMap, but RxPHP don’t provide mergeMap
  • 13. RxPHP $subject = new RxSubjectSubject(); $subject ->subscribe(function($i) { echo $i . PHP_EOL;}); RxObservable ::interval(1000) ->take(5) ->flatMap(function ($i) { return Observable ::of($i + 1); }) ->subscribe($subject); $subject ->onNext(10); $subject ->onNext(20); $subject ->onNext(30); // 10 // 20 // 30 // 1 // 2 // 3 // 4 // 5 Subject • Subject = Observable + Observer • Actually Subject is extended from Observable • You don’t need to create custom Observable for simple usage
  • 14. RxPHP More Samples • https://github.com/ReactiveX/RxPHP/tree/master/demo • https://github.com/PacktPublishing/PHP-Reactive- Programming/ • https://www.packtpub.com/web-development/php- reactive-programming
  • 15. RxPHP Ben Lesh’s comment RxJS could be so simple... just a handful of types and operators. ... but if we do that, then people shoot themselves in the foot with memory leaks and their own poorly implemented `expand` operator or whatever… ... so then we add 60+ operators and people are like "WHOA...." haha.. Now it's too complicated. It's tough everywhere. Haha If I had a nickel for every poorly implemented custom RxJS operator I've seen… ... I'd only have about 25 cents, because we've already built almost every tool someone could want. But who have we scared off in the process?