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

Serverless PHP @ PHPCon Poland 2019

Serverless PHP @ PHPCon Poland 2019

#serverless nie był do tej pory gorącym tematem w świecie PHP, ponieważ żaden z dostawców usług chmurowych nie wspiera natywnie PHP w środowisku tego typu. Pod koniec zeszłego roku AWS udostępniło dwie nowe usługi (Lambda Runtime API oraz Lambda Layers), które pozwalają na samodzielne dodanie PHP do środowiska typu #serveless. Podczas prezentacji omówię poszczególne elementy takiej architektury oraz pokażę kod PHP działąjacy na AWS Lambda.

Sebastian Grodzicki

November 16, 2019
Tweet

More Decks by Sebastian Grodzicki

Other Decks in Programming

Transcript

  1. phpinfo(); Sebastian Grodzicki
 • Engineering Manager at • ex-CTO at

    SHOWROOM & GoldenLine • PHP developer for 15+ years • #serverless @sebgrodzicki
  2. 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.
  3. 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,
  4. 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).
  5. 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
  6. service: app
 
 provider:
 name: aws
 region: us-east-1
 runtime: provided


    
 plugins:
 - ./vendor/bref/bref
 
 functions:
 api:
 handler: index.php
 description: ''
 timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
 layers:
 - ${bref:layer.php-73-fpm}
 events:
 - http: 'ANY /'
 - http: 'ANY /{proxy+}' serverless.yml
  7. $ serverless invoke -f function -l
 
 "Hello world"
 


    ------------------------------------------------------
 START RequestId: 71dd0550-46b4-4f13-8438-8f687f385d0c Version: $LATEST
 
 END RequestId: 71dd0550-46b4-4f13-8438-8f687f385d0c
 
 REPORT
 RequestId: 71dd0550-46b4-4f13-8438-8f687f385d0c Duration: 14.20 ms
 Billed Duration: 100 ms
 Memory Size: 1024 MB
 Max Memory Used: 67 MB CLI
  8. Benchmarks: Cold starts 128 512 1024 2048 PHP function 500

    ms 240 ms 230 ms 220 ms HTTP application 345 ms 250 ms 240 ms 240 ms Symfony 5.4 s 1.4 s 800 ms 500 ms
  9. Benchmarks: Average (warm) execution time 128 512 1024 2048 PHP

    function 175 ms 35 ms 16 ms 13 ms HTTP application 10 ms 1 ms 1 ms 1 ms Symfony 58 ms 4 ms 4 ms 4 ms
  10. Maturity matrix Simplicity Performances Reliability Jobs, Cron ⬤ ⬤ ⬤

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