$30 off During Our Annual Pro Sale. View Details »

Getting Started with Serverless PHP

Getting Started with Serverless PHP

These are the slides from a talk given at LonghornPHP 2022.

Some of us love to manage servers. But for a lot of PHP developers, servers are something we'd rather avoid. We're happy to pay hosting providers so we don't have to worry about it.

PHP hosting doesn't remove all your hosting headaches. You still have to worry about scaling. You're often overpaying for hosting because you have to worry about the worst-case scenario.

Well, that's what serverless PHP tries to solve. With serverless PHP, you only pay for what you use. Meanwhile, you get an infrastructure that can scale from handling zero traffic to thousands in seconds.

This talk will go over serverless PHP and how it works. We'll then look at the state of serverless in the PHP ecosystem. We'll finish by going over tools and projects you can use to deploy your PHP application on AWS Lambda.

You can read the companion article at: https://blog.ymirapp.com/getting-started-serverless-php

Carl Alexander

November 05, 2022
Tweet

More Decks by Carl Alexander

Other Decks in Technology

Transcript

  1. Getting Started with Serverless PHP

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

  3. “Servers. Can’t live with them. Can’t live without them.” -

    PHP developer (when a server blows up)
  4. Server management

  5. Still responsible

  6. Platform as a service

  7. Still need to over provision

  8. Serverless addresses these problems

  9. 1 What Is Serverless?

  10. “Are there really no servers with serverless!?” - Literally everyone

    I mention serverless to
  11. None
  12. Marketing term

  13. Functions as a Service

  14. On-demand computing

  15. Upload code to a cloud provider

  16. Code gets executed in response to an event

  17. No mention of servers

  18. Outside your sphere of concerns

  19. 2How Serverless PHP Works

  20. PHP with a web server

  21. None
  22. How does serverless PHP compare?

  23. Both run code in response to an event

  24. So what’s different?

  25. Not just PHP that runs without a server

  26. Everything is serverless

  27. Service based architecture

  28. None
  29. PHP runtime?

  30. Unique element of serverless PHP

  31. What does it do?

  32. Processes lambda event

  33. Figures out what the event wants

  34. Sends a result back (HTTP response)

  35. Mimics a web server

  36. Request a file, returns a file

  37. Creates FastCGI request, sends it to PHP-FPM

  38. Also manages the PHP-FPM process

  39. Stops the Lambda function after X requests

  40. Only one PHP-FPM worker

  41. Lambda only handles one event at a time

  42. Why PHP-FPM?

  43. Faster to have a running PHP process

  44. ?Questions

  45. 3Advantages of serverless PHP

  46. None
  47. No servers to manage

  48. Not everyone is comfortable with servers

  49. Still responsible

  50. PaaS solves this issue

  51. New problem. Scaling.

  52. Slow or not automated

  53. Each Lambda function is a PHP worker

  54. None
  55. Scaling in seconds not minutes

  56. None
  57. Need to plan for the worst with servers

  58. How much would that cost?

  59. None of that with serverless

  60. Usage based pricing

  61. Pay when your workers run

  62. Charged by the millisecond

  63. externals.io

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

  65. 4Drawbacks of Serverless PHP

  66. None
  67. Less predictable cost

  68. Paying for a server feels safe

  69. $X/month

  70. Need more performance? Pay more!

  71. None
  72. How many requests? Average duration?

  73. Stressful and harder to budget for

  74. Costs less

  75. What happens with constant load?

  76. Serverless not as attractive

  77. Possible to maximize server usage

  78. Optimal server might cost less

  79. AWS lock-in

  80. None
  81. Why not Azure or GCP?

  82. Not interchangeable

  83. Not just Lambda

  84. Need other services

  85. Equivalent ≠ Same

  86. Energy with AWS

  87. Final note

  88. Tempting to only compare cost

  89. “Serverless is expensive. I could just get a $5/month droplet

    from DigitalOcean.” - Someone comfortable with servers
  90. Dishonest

  91. Intangible costs

  92. Mental health

  93. Your time

  94. Be honest when you evaluate both options

  95. ?Questions

  96. 5Tools and Projects

  97. Where do you start?

  98. 98 Bref 7 https://bref.sh

  99. Open source project

  100. Mathieu Napoli

  101. PHP runtime

  102. Integrates with Symfony & Laravel

  103. Deploy with Serverless framework

  104. Extensive documentation

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

  106. Builds off Bref

  107. Deploys serverless Laravel applications

  108. Manages your entire serverless infrastructure

  109. None
  110. Good documentation

  111. serverlesslaravelcourse.com

  112. Paid product ($39/m + AWS bill)

  113. 113 7 Ymir https://ymirapp.com

  114. - Carl Alexander 👋 “This is amazing! I need to

    build this for WordPress.”
  115. Vapor for WordPress

  116. Does WordPress specific things

  117. HTML caching at edge

  118. Image optimizing CDN

  119. Same cost as Vapor

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

  121. 6Back to Simplicity

  122. PHP is so easy to use

  123. Hosting used to be simpler

  124. Serverless is deploy and forget

  125. Levels playing field

  126. ?Questions

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