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

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.

Sebastian Grodzicki

April 08, 2019
Tweet

More Decks by Sebastian Grodzicki

Other Decks in Programming

Transcript

  1. 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.
  2. 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).
  3. 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
  4. $ composer require mnapoli/bref $ vendor/bin/bref init $ aws s3

    mb s3://4developers $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket 4developers CLI
  5. $ 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
  6. $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket 4developers $

    sam deploy \
 --template-file .stack.yaml \
 --capabilities CAPABILITY_IAM \
 --stack-name php4developers CLI
  7. $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket 4developers $

    sam deploy \
 --template-file .stack.yaml \
 --capabilities CAPABILITY_IAM \
 --stack-name php4developers CLI
  8. 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
  9. 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
  10. Simplicity Performances Reliability Jobs, Cron ⬤ ⬤ ⬤ API ⬤

    ⬤ ⬤ API with MySQL / PostgreSQL ⬤ ⬤ ⬤ Website ⬤ ⬤ ⬤ Website with MySQL / PostgreSQL ⬤ ⬤ ⬤ Legacy application ⬤ ⬤ ⬤