Serverless PHP @ 4Developers 2019

Serverless PHP @ 4Developers 2019

#serverless wasn't a hot topic for PHP as none of the major cloud providers is offering native PHP support, but the new AWS Lambda runtime API and layers capabilities give us the ability to build a clean, supportable implementation of PHP on Lambda of our own. In this talk, we’ll take a brief look at the overall workflow and runtime lifecycle, and then I’ll show you how to run PHP on AWS Lambda.

9a328142924c93e5e148c75356ba6d42?s=128

Sebastian Grodzicki

April 08, 2019
Tweet

Transcript

  1. Serverless PHP Sebastian Grodzicki @ 4Developers 2019 @sebgrodzicki

  2. phpinfo() Sebastian Grodzicki
 • CTO at SHOWROOM • PHP developer

    for 15+ years • #serverless @sebgrodzicki
  3. SHOWROOM

  4. SHOWROOM

  5. Serverless • storage as a service (e.g. Amazon S3), •

    database as a service (e.g. Amazon Aurora), • message queue as a service (e.g. Amazon SQS), • etc.
  6. Serverless replaces the traditional approaches to running applications.

  7. Platform options Physical servers Virtual machines Containers Platform Serverless Abstraction

    Control
  8. Why serverless? • We don't manage, update, configure, provision servers

    or containers, • We don't reserve or scale servers or containers, instead they are scaled automatically and transparently for us, • We don't pay for fixed resources, instead we pay for what we actually use (e.g. execution time).
  9. Serverless can provide more scalable, affordable and reliable architectures for

    less effort.
  10. Data center evolution DC

  11. Data center evolution DC VM VM VM VM VM VM

    VM VM VM VM VM VM
  12. Data center evolution DC VM C C C C C

    C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C VM C C C C C C
  13. Data center evolution 
 DNS 
 CDN

  14. Data center evolution PaaS IaaS SaaS

  15. Function as a Service (FaaS)

  16. FaaS AWS Lambda Microsoft Azure Functions Google Cloud Functions

  17. Bref

  18. $ composer require mnapoli/bref CLI

  19. $ composer require mnapoli/bref $ vendor/bin/bref init CLI

  20. <?php
 
 echo 'Hello world!'; index.php

  21. $ composer require mnapoli/bref $ vendor/bin/bref init $ aws s3

    mb s3://4developers CLI
  22. $ composer require mnapoli/bref $ vendor/bin/bref init $ aws s3

    mb s3://4developers $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket 4developers CLI
  23. $ composer require mnapoli/bref $ vendor/bin/bref init $ aws s3

    mb s3://4developers $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket 4developers $ sam deploy \
 --template-file .stack.yaml \
 --capabilities CAPABILITY_IAM \
 --stack-name php4developers CLI
  24. None
  25. <?php
 
 echo 'Hello 4Developers!'; index.php

  26. $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket 4developers $

    sam deploy \
 --template-file .stack.yaml \
 --capabilities CAPABILITY_IAM \
 --stack-name php4developers CLI
  27. None
  28. <?php
 
 phpinfo(); index.php

  29. $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket 4developers $

    sam deploy \
 --template-file .stack.yaml \
 --capabilities CAPABILITY_IAM \
 --stack-name php4developers CLI
  30. None
  31. None
  32. None
  33. None
  34. None
  35. None
  36. Benchmarks: Cold starts 128 512 1024 2048 PHP function 600

    ms 280 ms 225 ms 215 ms HTTP application 500 ms 270 ms 270 ms 215 ms Symfony 5.6 s 1.7 s 850 ms 550 ms
  37. Benchmarks: Average (warm) execution time 128 512 1024 2048 PHP

    function 130 ms 32 ms 20 ms 17 ms HTTP application 13 ms 5 ms 3 ms 2 ms Symfony 56 ms 12 ms 6 ms 5 ms
  38. Benchmarks: CPU performance 128 512 1024 2048 bench.php 6 s

    1.8 s 0.8 s 0.4 s
  39. Simplicity Performances Reliability Jobs, Cron ⬤ ⬤ ⬤ API ⬤

    ⬤ ⬤ API with MySQL / PostgreSQL ⬤ ⬤ ⬤ Website ⬤ ⬤ ⬤ Website with MySQL / PostgreSQL ⬤ ⬤ ⬤ Legacy application ⬤ ⬤ ⬤
  40. PrettyCI

  41. PrettyCI

  42. PrettyCI

  43. PrettyCI

  44. Questions?

  45. OPcache

  46. Thank you!