Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ebb and Flow - Event Driven Applications

Ebb and Flow - Event Driven Applications

Bob Majdak Jr

June 28, 2013
Tweet

More Decks by Bob Majdak Jr

Other Decks in Programming

Transcript

  1. Ebb and Flow Ebb and Flow Event Driven Applications in

    PHP Event Driven Applications in PHP
  2. This Guy This Guy • Bob Majdak Jr Bob Majdak

    Jr • @bobmajdakjr @bobmajdakjr • github/bobmajdakjr github/bobmajdakjr – PHP-GTK PHP-GTK – Imagick Imagick – Frameworking Frameworking
  3. 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
  4. 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
  5. 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.
  6. 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
  7. 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.
  8. 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
  9. Causing Events To Happen Causing Events To Happen • Events

    can be Events can be – Emitted... Emitted... – Signaled... Signaled... – Thrown... Thrown... – Sent... Sent... – Announced... Announced...
  10. 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.
  11. 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
  12. 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
  13. 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.
  14. Show them the goofy demo, Bob. Show them the goofy

    demo, Bob. (LSP13-EF1) (LSP13-EF1)
  15. 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?
  16. “It’s NodeJS, for PHP” – Bob (who is prone to

    overgeneralizing things) https://speakerdeck.com/igorw/react-phpbnl13
  17. 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.
  18. 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)
  19. 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.