Slide 1

Slide 1 text

Getting Started with Serverless PHP

Slide 2

Slide 2 text

2 Heya! 2 I’m Carl Alexander @twigpress carlalexander.ca

Slide 3

Slide 3 text

“Servers. Can’t live with them. Can’t live without them.” - PHP developer (when a server blows up)

Slide 4

Slide 4 text

Server management

Slide 5

Slide 5 text

Still responsible

Slide 6

Slide 6 text

Platform as a service

Slide 7

Slide 7 text

Still need to over provision

Slide 8

Slide 8 text

Serverless addresses these problems

Slide 9

Slide 9 text

1 What Is Serverless?

Slide 10

Slide 10 text

“Are there really no servers with serverless!?” - Literally everyone I mention serverless to

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Marketing term

Slide 13

Slide 13 text

Functions as a Service

Slide 14

Slide 14 text

On-demand computing

Slide 15

Slide 15 text

Upload code to a cloud provider

Slide 16

Slide 16 text

Code gets executed in response to an event

Slide 17

Slide 17 text

No mention of servers

Slide 18

Slide 18 text

Outside your sphere of concerns

Slide 19

Slide 19 text

2How Serverless PHP Works

Slide 20

Slide 20 text

PHP with a web server

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

How does serverless PHP compare?

Slide 23

Slide 23 text

Both run code in response to an event

Slide 24

Slide 24 text

So what’s different?

Slide 25

Slide 25 text

Not just PHP that runs without a server

Slide 26

Slide 26 text

Everything is serverless

Slide 27

Slide 27 text

Service based architecture

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

PHP runtime?

Slide 30

Slide 30 text

Unique element of serverless PHP

Slide 31

Slide 31 text

What does it do?

Slide 32

Slide 32 text

Processes lambda event

Slide 33

Slide 33 text

Figures out what the event wants

Slide 34

Slide 34 text

Sends a result back (HTTP response)

Slide 35

Slide 35 text

Mimics a web server

Slide 36

Slide 36 text

Request a file, returns a file

Slide 37

Slide 37 text

Creates FastCGI request, sends it to PHP-FPM

Slide 38

Slide 38 text

Also manages the PHP-FPM process

Slide 39

Slide 39 text

Stops the Lambda function after X requests

Slide 40

Slide 40 text

Only one PHP-FPM worker

Slide 41

Slide 41 text

Lambda only handles one event at a time

Slide 42

Slide 42 text

Why PHP-FPM?

Slide 43

Slide 43 text

Faster to have a running PHP process

Slide 44

Slide 44 text

?Questions

Slide 45

Slide 45 text

3Advantages of serverless PHP

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No servers to manage

Slide 48

Slide 48 text

Not everyone is comfortable with servers

Slide 49

Slide 49 text

Still responsible

Slide 50

Slide 50 text

PaaS solves this issue

Slide 51

Slide 51 text

New problem. Scaling.

Slide 52

Slide 52 text

Slow or not automated

Slide 53

Slide 53 text

Each Lambda function is a PHP worker

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Scaling in seconds not minutes

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Need to plan for the worst with servers

Slide 58

Slide 58 text

How much would that cost?

Slide 59

Slide 59 text

None of that with serverless

Slide 60

Slide 60 text

Usage based pricing

Slide 61

Slide 61 text

Pay when your workers run

Slide 62

Slide 62 text

Charged by the millisecond

Slide 63

Slide 63 text

externals.io

Slide 64

Slide 64 text

$50/m -> $~17/m ($16/m is RDS)

Slide 65

Slide 65 text

4Drawbacks of Serverless PHP

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Less predictable cost

Slide 68

Slide 68 text

Paying for a server feels safe

Slide 69

Slide 69 text

$X/month

Slide 70

Slide 70 text

Need more performance? Pay more!

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

How many requests? Average duration?

Slide 73

Slide 73 text

Stressful and harder to budget for

Slide 74

Slide 74 text

Costs less

Slide 75

Slide 75 text

What happens with constant load?

Slide 76

Slide 76 text

Serverless not as attractive

Slide 77

Slide 77 text

Possible to maximize server usage

Slide 78

Slide 78 text

Optimal server might cost less

Slide 79

Slide 79 text

AWS lock-in

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

Why not Azure or GCP?

Slide 82

Slide 82 text

Not interchangeable

Slide 83

Slide 83 text

Not just Lambda

Slide 84

Slide 84 text

Need other services

Slide 85

Slide 85 text

Equivalent ≠ Same

Slide 86

Slide 86 text

Energy with AWS

Slide 87

Slide 87 text

Final note

Slide 88

Slide 88 text

Tempting to only compare cost

Slide 89

Slide 89 text

“Serverless is expensive. I could just get a $5/month droplet from DigitalOcean.” - Someone comfortable with servers

Slide 90

Slide 90 text

Dishonest

Slide 91

Slide 91 text

Intangible costs

Slide 92

Slide 92 text

Mental health

Slide 93

Slide 93 text

Your time

Slide 94

Slide 94 text

Be honest when you evaluate both options

Slide 95

Slide 95 text

?Questions

Slide 96

Slide 96 text

5Tools and Projects

Slide 97

Slide 97 text

Where do you start?

Slide 98

Slide 98 text

98 Bref 7 https://bref.sh

Slide 99

Slide 99 text

Open source project

Slide 100

Slide 100 text

Mathieu Napoli

Slide 101

Slide 101 text

PHP runtime

Slide 102

Slide 102 text

Integrates with Symfony & Laravel

Slide 103

Slide 103 text

Deploy with Serverless framework

Slide 104

Slide 104 text

Extensive documentation

Slide 105

Slide 105 text

105 Laravel Vapor 7 https://vapor.laravel.com

Slide 106

Slide 106 text

Builds off Bref

Slide 107

Slide 107 text

Deploys serverless Laravel applications

Slide 108

Slide 108 text

Manages your entire serverless infrastructure

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

Good documentation

Slide 111

Slide 111 text

serverlesslaravelcourse.com

Slide 112

Slide 112 text

Paid product ($39/m + AWS bill)

Slide 113

Slide 113 text

113 7 Ymir https://ymirapp.com

Slide 114

Slide 114 text

- Carl Alexander 👋 “This is amazing! I need to build this for WordPress.”

Slide 115

Slide 115 text

Vapor for WordPress

Slide 116

Slide 116 text

Does WordPress specific things

Slide 117

Slide 117 text

HTML caching at edge

Slide 118

Slide 118 text

Image optimizing CDN

Slide 119

Slide 119 text

Same cost as Vapor

Slide 120

Slide 120 text

120 Sidecar 7 https://github.com/ hammerstonedev/sidecar (Bonus!)

Slide 121

Slide 121 text

6Back to Simplicity

Slide 122

Slide 122 text

PHP is so easy to use

Slide 123

Slide 123 text

Hosting used to be simpler

Slide 124

Slide 124 text

Serverless is deploy and forget

Slide 125

Slide 125 text

Levels playing field

Slide 126

Slide 126 text

?Questions

Slide 127

Slide 127 text

127 Thank you! 2 @twigpress carlalexander.ca joind.in/talk/f8b79