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

High-Speed Modern Web Apps with PHP & AMF

High-Speed Modern Web Apps with PHP & AMF

JSON has become the lingua-franca between web developers and APIs, but it has some critical limitations that stunt some possibilities of modern web development.

In this somewhat esoteric talk, I will discuss the possibility of using AMF - a binary data-interchange protocol - in web applications, using PHP & JavaScript. AMF allows for a wider array of data type encodings, circular references, and more. AMF has been used with Flash applications for years, is tried and true - and, as I will hopefully convince you, should be used in modern web applications.

Dougie Crockford, you're on.

Danny Kopping

April 05, 2014
Tweet

More Decks by Danny Kopping

Other Decks in Programming

Transcript

  1. High-Speed Modern
    Web Apps with
    PHP & AMF
    Danny Kopping
    #PHPJoburg14

    View Slide

  2. • Mid-twenties
    • Senior PHP Developer @ Zando.co.za
    • Born ‘n’ raised in Joburg
    • Resident of Cape Town
    Bio

    View Slide

  3. The Lay of the Land

    View Slide

  4. Model → Data Layer
    View → Presentation Layer
    Controller → Logic Layer
    MVC

    View Slide

  5. Model → Data Layer
    View → Presentation Layer
    Controller → Logic Layer
    MVC

    View Slide

  6. A brief,
    mostly wrong
    (& somewhat offensive)
    history of
    Web development

    View Slide

  7. 1989
    Sir Tim Berners-Lee has difficulty finding porn.
    Oh, and some academic shit.

    View Slide

  8. 1989
    Like Facebook, the web was born in a university.
    ...and spread to other universities.

    View Slide

  9. 1991
    The first HTTP spec is written.
    It’s one page long.
    You can use GET.

    View Slide

  10. 1993
    The first Web browsers start to take shape.

    View Slide

  11. 1994
    Python, PHP, Ruby & Perl
    are all dra#ed/created/released
    Not a
    swastika

    View Slide

  12. 1994
    SSL is developed

    View Slide

  13. 1995
    IE 1.0 is released.

    View Slide

  14. 1995
    Oh, and Opera is released too.
    Its userbase has not grown much since.

    View Slide

  15. 1995
    HTML 3.0 is released.
    CSS 0.92 is released.

    View Slide

  16. 1995
    JavaScript is created by Brendan Eich.
    In 10 days.
    It sometimes shows.
    This is how much I
    hate gay marriage

    View Slide

  17. 1995
    Java Applets are introduced.
    SmartSketch
    FutureSplash
    Flash is created.
    The dawn of Rich Internet Applications is born.

    View Slide

  18. 1995
    Apache is released

    View Slide

  19. 1996
    HTTP 1.0 is released.
    The spec has now grown to 70 pages.
    Woohoo, POST!

    View Slide

  20. 1996
    XML 1.0 is defined.

    View Slide

  21. 1998
    SOAP is designed and released.
    POST /InStock HTTP/1.1
    Host: www.example.org
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: 299
    SOAPAction: "http://www.w3.org/2003/05/soap-envelope"







    IBM



    View Slide

  22. 1999
    HTTP 1.1 is released.
    The spec has now grown to 176 pages.
    PUT, DELETE now available.

    View Slide

  23. 2001
    JSON is invented by good ol’ Douglas Crockford

    View Slide

  24. 2002
    Mozilla Firefox hits 1.0

    View Slide

  25. 2005
    JSON explosion
    AJAX makes its way onto the scene

    View Slide

  26. A DECADE
    PASSES...

    View Slide

  27. 2014
    Ooh, it’s now responsive...

    View Slide

  28. and the data?

    View Slide

  29. Pretty much stuck in
    the early 2000s.

    View Slide


  30. View Slide

  31. View Slide

  32. (not to scale)

    View Slide

  33. View Slide

  34. LOL.

    View Slide


  35. View Slide

  36. I used to code in Flash.
    The Dirty
    Little Secret
    ...and I miss it.

    View Slide

  37. Yup.
    I said it.

    View Slide

  38. What made Flash
    wonderful?

    View Slide

  39. • Consistent UI across all browsers
    • Great scripting language (ActionScript 3.0)
    • Based on ECMAScript 262 (JavaScript)
    • AMF

    View Slide

  40. Another
    Motherfucking
    Format

    View Slide

  41. Action
    Message
    Format
    Created by Adobe

    View Slide

  42. What is AMF?

    View Slide

  43. What is AMF?

    View Slide

  44. • Binary data serialization protocol
    What is AMF?

    View Slide

  45. • Binary data serialization protocol
    • Originally used in Flash 6 / ActionScript 2.0
    What is AMF?

    View Slide

  46. • Binary data serialization protocol
    • Originally used in Flash 6 / ActionScript 2.0
    • Two major versions: AMF0 & AMF3
    What is AMF?

    View Slide

  47. • Binary data serialization protocol
    • Originally used in Flash 6 / ActionScript 2.0
    • Two major versions: AMF0 & AMF3
    • Support for 18 distinct data types
    What is AMF?

    View Slide

  48. • Binary data serialization protocol
    • Originally used in Flash 6 / ActionScript 2.0
    • Two major versions: AMF0 & AMF3
    • Support for 18 distinct data types
    • Many libraries available across several
    languages and platforms
    What is AMF?

    View Slide

  49. • Binary data serialization protocol
    • Originally used in Flash 6 / ActionScript 2.0
    • Two major versions: AMF0 & AMF3
    • Support for 18 distinct data types
    • Many libraries available across several
    languages and platforms
    • Compression, data efficiency (references)
    What is AMF?

    View Slide

  50. • Binary data serialization protocol
    • Originally used in Flash 6 / ActionScript 2.0
    • Two major versions: AMF0 & AMF3
    • Support for 18 distinct data types
    • Many libraries available across several
    languages and platforms
    • Compression, data efficiency (references)
    • Reconstruct object state across tiers
    What is AMF?

    View Slide

  51. • Binary data serialization protocol
    • Originally used in Flash 6 / ActionScript 2.0
    • Two major versions: AMF0 & AMF3
    • Support for 18 distinct data types
    • Many libraries available across several
    languages and platforms
    • Compression, data efficiency (references)
    • Reconstruct object state across tiers
    • Can be GZIPed
    What is AMF?

    View Slide

  52. Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  53. • Infomaniac-AMF supports 10 data types
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  54. • Infomaniac-AMF supports 10 data types
    • JS & PHP libs available
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  55. • Infomaniac-AMF supports 10 data types
    • JS & PHP libs available
    • Fast-ish
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  56. • Infomaniac-AMF supports 10 data types
    • JS & PHP libs available
    • Fast-ish
    • Unit-tested
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  57. • Infomaniac-AMF supports 10 data types
    • JS & PHP libs available
    • Fast-ish
    • Unit-tested
    • Lightweight
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  58. • Infomaniac-AMF supports 10 data types
    • JS & PHP libs available
    • Fast-ish
    • Unit-tested
    • Lightweight
    • Aims to be a drop-in replacement for JSON
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  59. • Infomaniac-AMF supports 10 data types
    • JS & PHP libs available
    • Fast-ish
    • Unit-tested
    • Lightweight
    • Aims to be a drop-in replacement for JSON
    • AMF.stringify(obj, options)
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  60. • Infomaniac-AMF supports 10 data types
    • JS & PHP libs available
    • Fast-ish
    • Unit-tested
    • Lightweight
    • Aims to be a drop-in replacement for JSON
    • AMF.stringify(obj, options)
    • AMF.parse(amfData)
    Introducing...
    http://github.com/infomaniac-amf
    Infomaniac-AMF

    View Slide

  61. Data types
    http://github.com/infomaniac-amf
    Infomaniac-AMF
    UNDEFINED NULL BOOLEAN INT
    DOUBLE STRING ARRAY OBJECT
    BYTE-ARRAY DATE

    View Slide

  62. AMF is the future.
    ...or what the future could be like.

    View Slide

  63. Should JSON/XML die?
    No.
    Is AMF better than x?
    Not necessarily.

    View Slide

  64. Oh demo gods...
    Grant me luck!

    View Slide

  65. CODE DEMO

    View Slide