Save 37% off PRO during our Black Friday Sale! »

True North WebSocket talk

E64cdd88cc31a6f8423237f38a0c97eb?s=47 Chris Boden
November 02, 2012

True North WebSocket talk

E64cdd88cc31a6f8423237f38a0c97eb?s=128

Chris Boden

November 02, 2012
Tweet

Transcript

  1. WebSockets Bring your site to life using joind.in/7407

  2. @boden_c •Ratchet •React Chris

  3. What Are WebSockets ? Push Real-time Bi-directional Live

  4. Use cases • Notifications • Chat/Communication • Statistics • Games

    • Anything/Everything
  5. But...Can’t we do that today? Comet

  6. How Comet over HTTP works

  7. it’s slow it’s hard to develop it wastes bandwidth ...and

    what’s wrong with that it’s a square peg for a round hole
  8. That’s a lot of requests! (sorry for throwing you under

    the bus Travis. I still <3 you!)
  9. How Sockets Work • Client connects to server • Server

    accepts connection • An open connection is established/maintained • Client/Server sends message to each other
  10. None
  11. Network Topology

  12. Synchronous Stack Your Traditional Server Processes nginx:80 php-fpm php-fpm php-fpm

    php-fpm Your app’s source code Storage
  13. The Event Loop

  14. DEMO TIME!!! Open your terminals and... $ telnet demo.socketo.me 8080

  15. WebSocket Recipe + RFC6455 WebSocket Protocol (PHP) HTML5 WebSocket API

    (JavaScript) = goodness
  16. Development Server AND Client share 4 simple events

  17. (speaker note: duck)

  18. It doesn’t! ...much... It’s getting better!

  19. A Shameless Plug Introducing: Ratchet

  20. Ratchet is A pure PHP library to serve WebSockets; it

    is: • RFC6455 compliant • asynchronous • unit tested (hi Mr. Grumpy) • loosely coupled • ready to lose limbs
  21. Fun with Numbers Remember how PHP “sucked”?

  22. The anatomy of a Ratchet application: Look familiar?

  23. the actual logic execute the server Full Chat: under 50

    loc!
  24. Ratchet Architecture The Decorator design pattern

  25. Components

  26. The Client (JavaScript)

  27. DEMO TIME!!! Open Chrome or Firefox and open your debug

    console
  28. 4.0+ (2009) 6.0+ (2011) 10.70+ (2012) 5.0+ (2010) 10+ (2012)

  29. Supporting the unsupported Browsers • IE7 • IE8 • IE9

  30. ...I saw this the other day... seems legit?

  31. 2 Options SockJS Flash

  32. Flash • Very easy to implement • True pollyfill •

    They’re IE users anyway • It’s Flash... • Up to 3 second connect • Port blocked by proxies Pros Cons
  33. SockJS • Future proof • Uses native fallbacks • Community

    support • No PHP implementation • No sub-protocol support Pros Cons
  34. Going Polyglot

  35. How do we communicate? It’s all about sockets

  36. PHP/Python/Java/Node/Ruby socket or MQ (sync) (async)

  37. DNode ZeroMQ

  38. Practical Development

  39. Today’s Issues • Proxies • Scaling • Use SSL •

    ??? Problem Solution (time solves all problems)
  40. Questions? • @boden_c • socketo.me • github.com/cboden/Ratchet • github.com/reactphp •

    joind.in/7407