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

Serverless PHP @ SymfonyLive Warszawa 2019

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Serverless PHP @ SymfonyLive Warszawa 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

June 14, 2019

Transcript

40 slides
  1. phpinfo() Sebastian Grodzicki
 • Team Lead at • 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, • We don't pay for fixed resources, instead we pay for what we actually use (e.g. execution time).
  4. 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
  5. AWSTemplateFormatVersion: '2010-09-09'
 Transform: AWS::Serverless-2016-10-31
 Description: ''
 
 Resources:
 MyFunction:
 Type:

    AWS::Serverless::Function
 Properties:
 FunctionName: 'my-function'
 Description: ''
 CodeUri: .
 Handler: index.php
 Timeout: 10
 MemorySize: 1024
 Runtime: provided
 Layers:
 - 'arn:aws:lambda:eu- central-1:209497400698:layer:php-73:6' template.yaml
  6. $ composer require bref/bref $ vendor/bin/bref init $ aws s3

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

    mb s3://symfonylive $ sam package \
 --output-template-file .stack.yaml \
 --s3-bucket symfonylive $ sam deploy \
 --template-file .stack.yaml \
 --capabilities CAPABILITY_IAM \
 --stack-name SymfonyLive CLI
  8. $ vendor/bin/bref invoke my-function
 
 START RequestId: 745a76df-fddc-4cb4-b826-e169d43c67d3 Version: $LATEST


    
 END RequestId: 745a76df-fddc-4cb4-b826-e169d43c67d3
 
 REPORT RequestId: 745a76df-fddc-4cb4-b826-e169d43c67d3 Duration: 13.65 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 63 MB 
 
 "Hello world" CLI
  9. $ vendor/bin/bref invoke my-function --event '{"name":"SymfonyLive"}'
 
 START RequestId: e44bd988-16aa-4a36-abf1-3924acfb7d42

    Version: $LATEST
 
 END RequestId: e44bd988-16aa-4a36-abf1-3924acfb7d42
 
 REPORT RequestId: e44bd988-16aa-4a36-abf1-3924acfb7d42 Duration: 13.27 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 63 MB 
 
 "Hello SymfonyLive" CLI
  10. 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
  11. 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
  12. Simplicity Performances Reliability Jobs, Cron ⬤ ⬤ ⬤ API ⬤

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

More Decks by Sebastian Grodzicki

Other Decks in Programming