Slide 1

Slide 1 text

Ebb and Flow Ebb and Flow Event Driven Applications in PHP Event Driven Applications in PHP

Slide 2

Slide 2 text

This Guy This Guy ● Bob Majdak Jr Bob Majdak Jr ● @bobmajdakjr @bobmajdakjr ● github/bobmajdakjr github/bobmajdakjr – PHP-GTK PHP-GTK – Imagick Imagick – Frameworking Frameworking

Slide 3

Slide 3 text

Story Time Story Time https://joind.in/8700 https://joind.in/8700

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

The Typical PHP App The Typical PHP App ● Page hit, instance begins. Page hit, instance begins. – Initialize Initialize – Configure Configure – Setup Setup – Ready Ready ● Input (handle GET, POST, decide what to do) Input (handle GET, POST, decide what to do) ● Main (do what was decided) Main (do what was decided) ● Output (toss it out to the browser, themed) Output (toss it out to the browser, themed) – Shutdown Shutdown

Slide 6

Slide 6 text

Events are... Events are... Things that happen. Things that happen. (I know, right?) (I know, right?)

Slide 7

Slide 7 text

Strictly Synchronous EBS Strictly Synchronous EBS ● Page hit, instance begins. Page hit, instance begins. – Initialize Initialize – Configure Configure – Setup Setup – Ready Ready ● Input Input ● Main Main ● Output Output – Shutdown Shutdown Your Framework Your Framework and Libraries and Libraries Your App Your App

Slide 8

Slide 8 text

Notable Event System Styles Notable Event System Styles ● Loosely Synchronous Loosely Synchronous – Basis of a solid Basis of a solid plug-in system. plug-in system. ● Asynchronous Asynchronous – Basis of a queue Basis of a queue service. service.

Slide 9

Slide 9 text

Loosely Synchronous Event Systems Loosely Synchronous Event Systems ● Symfony2 EventDispatcher (Standalone) Symfony2 EventDispatcher (Standalone) – https://github.com/symfony/EventDispatcher https://github.com/symfony/EventDispatcher ● Monticello Ki (Standalone) Monticello Ki (Standalone) – https://github.com/monticello/ki https://github.com/monticello/ki ● Yii (Full Stack) Yii (Full Stack) – http://www.yiiframework.com/wiki/327/events-explained/ http://www.yiiframework.com/wiki/327/events-explained/ ● CodeIgniter-Events (Add On) CodeIgniter-Events (Add On) – https://github.com/ericbarnes/CodeIgniter-Events https://github.com/ericbarnes/CodeIgniter-Events ● WordPress (LOLStack) WordPress (LOLStack) – http://wordpress.org http://wordpress.org

Slide 10

Slide 10 text

How to Accidentally a Plug In System How to Accidentally a Plug In System With Events and Things. With Events and Things. ● Announce you are about to do something before you do it. Announce you are about to do something before you do it. – Allows a plugin to watch for this and do something else instead. Allows a plugin to watch for this and do something else instead. ● Announce you just set a new value after you set it. Announce you just set a new value after you set it. – Allows a plugin to watch for this to either filter or completely Allows a plugin to watch for this to either filter or completely change a value. change a value. ● Announce whenever an application milestone has been reached. Announce whenever an application milestone has been reached. – Allows a plugin to prepare functionality for later stages, or Allows a plugin to prepare functionality for later stages, or modify the output of what just happened. modify the output of what just happened. ● Announce whenever an error occurs. Announce whenever an error occurs. – Allows a plugin to perhaps attempt a recovery, or log the error, Allows a plugin to perhaps attempt a recovery, or log the error, or explode in a more grandiose way. or explode in a more grandiose way.

Slide 11

Slide 11 text

Strictly Synchronous EBS Strictly Synchronous EBS ● Page hit, instance begins. Page hit, instance begins. – Initialize Initialize – Configure Configure – Setup Setup – Ready Ready ● Input Input ● Main Main ● Output Output – Shutdown Shutdown Your Framework Your Framework and Libraries and Libraries Your App Your App

Slide 12

Slide 12 text

A Basic Base A Basic Base

Slide 13

Slide 13 text

Causing Events To Happen Causing Events To Happen ● Events can be Events can be – Emitted... Emitted... – Signaled... Signaled... – Thrown... Thrown... – Sent... Sent... – Announced... Announced...

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Responding To Events That Happened Responding To Events That Happened ● Events must be... Events must be... – Handled... Handled... – Listened for... Listened for... – Watched for.. Watched for.. – Caught... Caught... – Received.. Received.. – … … or ignored. or ignored.

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Connecting the User and the Cache Connecting the User and the Cache

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Events for Events Events for Events

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Visualize: User, Cache, Logger (Dev) Visualize: User, Cache, Logger (Dev) $user = User::Get(42) Cache Library user-get user-42 I see what she did there. Here take my user-42. Log Library I heard you had a cache hit. I am gonna make a note of that in the debugging log. cache-get-hit user-42

Slide 23

Slide 23 text

Visualize: User, Cache, Logger (Prod) Visualize: User, Cache, Logger (Prod) $user = User::Get(42) Cache Library user-get user-42 I see what she did there. Here take my user-42. Log Library

Slide 24

Slide 24 text

The Building Blocks of Extendability The Building Blocks of Extendability ● Intercepting Behaviour Intercepting Behaviour – Modifying / Filtering Modifying / Filtering – Blocking Blocking ● Adding Behaviour Adding Behaviour – Drag and Drop Features Drag and Drop Features ● Events can happen ANYWHERE. Events can happen ANYWHERE.

Slide 25

Slide 25 text

Show them the goofy demo, Bob. Show them the goofy demo, Bob. (LSP13-EF1) (LSP13-EF1)

Slide 26

Slide 26 text

Asynchronous Events Asynchronous Events ● Processing of an event does not prevent other Processing of an event does not prevent other events from being handled at the same time. events from being handled at the same time. – NodeJS NodeJS – Twisted (Python) Twisted (Python) – AJAX (jQuery makes it easy) AJAX (jQuery makes it easy) – GTK/Glib (and probably other GUI toolkits) GTK/Glib (and probably other GUI toolkits) – But, PHP? But, PHP?

Slide 27

Slide 27 text

“It’s NodeJS, for PHP” – Bob (who is prone to overgeneralizing things) https://speakerdeck.com/igorw/react-phpbnl13

Slide 28

Slide 28 text

React PHP React PHP ● Queue management... Queue management... – A stand alone service that has one job: keep a A stand alone service that has one job: keep a list of things that need to get done and tell list of things that need to get done and tell clients the next thing to do when they say they clients the next thing to do when they say they are done with whatever they just did. are done with whatever they just did. ● Live Communications... Live Communications... – Chat, Game Data, Task Status Updates... Chat, Game Data, Task Status Updates... – I could have written an IRC server demo but I could have written an IRC server demo but that would have been so 1988. that would have been so 1988.

Slide 29

Slide 29 text

React PHP – The quick jist. React PHP – The quick jist. ● Start the service. Start the service. ● Begin listening for clients. Begin listening for clients. – Client connected? Assign functions to handle when Client connected? Assign functions to handle when the new connection sends data. the new connection sends data. ● Supports multiple back ends: Supports multiple back ends: – PHP Streams (stream_select). Just works. Not the PHP Streams (stream_select). Just works. Not the fastest, but still faster than you. fastest, but still faster than you. – LibEvent (PECL wrapper of the C lib) LibEvent (PECL wrapper of the C lib) – LibEV (PECL wrapper of the C lib) LibEV (PECL wrapper of the C lib)

Slide 30

Slide 30 text

Simple React TCP Server Simple React TCP Server

Slide 31

Slide 31 text

Extending React Server Extending React Server

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

A React Event Client A React Event Client

Slide 34

Slide 34 text

Other React Classes Other React Classes ● React\SocketClient\Connector React\SocketClient\Connector – Promise Based Quick Client Promise Based Quick Client ● React\Http\Server React\Http\Server – Similar to the Socket Server, but with extra events for Similar to the Socket Server, but with extra events for serving HTTP requests easier. REST server? serving HTTP requests easier. REST server? ● React\HttpClient\Client React\HttpClient\Client – Event based HTTP client. REST client? Event based HTTP client. REST client? – Still has some important development TODO’s before Still has some important development TODO’s before being complete. being complete.

Slide 35

Slide 35 text

Show them the baseball demo, Bob. Show them the baseball demo, Bob.