We're sunsetting PodQuest on 2025-07-28. Thank you for your support!
Export Podcast Subscriptions
cover of episode #109: Building serverless apps in PHP with Bref | ft Matthieu Napoli

#109: Building serverless apps in PHP with Bref | ft Matthieu Napoli

2024/10/24
logo of podcast Real World Serverless with theburningmonk

Real World Serverless with theburningmonk

AI Deep Dive AI Chapters Transcript
People
M
Matthieu Napoli
主持人
专注于电动车和能源领域的播客主持人和内容创作者。
Topics
Matthieu Napoli: 我是一名在法国工作的顾问,主要从事Bref相关的业务,创建无服务器应用程序。我从事无服务器开发是因为我不喜欢做系统管理员的工作,我希望开发过程简单便捷。2017年,我开始创建Bref项目,旨在让PHP运行在Lambda上。Bref是一个开源的PHP运行时,允许在Lambda上运行PHP和PHP框架。Bref利用Lambda的自定义运行时功能,提供了一个PHP运行时环境。Bref提供了一个自定义运行时(也称为层),包含PHP二进制文件和必要的连接代码。使用Bref的自定义运行时,PHP开发者无需关心如何在Lambda上运行PHP。Bref使用Serverless Framework进行部署,并通过插件添加对PHP运行时的支持。Bref使用Composer(PHP的包管理器)进行安装,避免了对NPM的依赖。Bref的设计目标是让PHP开发者无需了解Node.js生态系统。Bref支持Serverless Framework v3和v4,并计划长期支持v3。Bref正在开发更简单的PHP应用程序部署方式,以替代Serverless Framework。Bref支持部署各种PHP应用程序,包括Laravel和Symfony应用。大多数PHP应用都需要数据库,Bref正在开发更简单的部署方式来满足这一需求。Bref使用`serverless deploy`命令进行部署。Bref成功地将单体应用部署到Lambda上。许多公司成功地将单体应用或使用Laravel或Symfony框架构建的应用部署到单个Lambda函数中。使用Bref可以将Laravel或Symfony应用程序部署到单个Lambda函数中。将Laravel或Symfony应用程序拆分成多个Lambda函数工作量很大,并且会失去框架的优势。将Express.js替换为API Gateway不会损失太多功能,但将Laravel替换为API Gateway会损失很多功能。对于处理队列和事件,建议使用多个Lambda函数。Laravel框架提供了许多开箱即用的功能,例如身份验证、授权和密码管理。Laravel框架提供了开箱即用的身份验证功能,包括多因素身份验证和密码轮换。Laravel框架提供了开箱即用的权限系统,可以根据角色和权限控制访问。如果将身份验证从Laravel框架中分离出来,将会失去很多功能。是否将应用与框架解耦,取决于公司的目标和需求。是否将应用与AWS解耦,取决于公司的目标和需求。Bref的目标是提供与Laravel Vapor类似的用户体验,同时保持CloudFormation的灵活性。BrefCloud项目旨在提供更简单的配置体验,并支持自托管功能。Bref的目标用户是希望轻松部署可扩展应用程序,而不是成为AWS专家的用户。Bref的两个运行时:一个用于运行PHP FPM,另一个用于运行非HTTP任务。使用PHP FPM运行时的冷启动时间约为300毫秒。使用非PHP FPM运行时的冷启动时间约为250毫秒。Laravel应用程序的冷启动时间可能高达1秒。可以通过预缓存来优化冷启动时间。可以通过预编译视图和配置文件来优化冷启动时间。单体应用可能比多个函数的应用冷启动次数更少。Bref正在开发v3版本,并计划支持Lambda Streaming Response。 主持人: PHP的执行模型与Lambda类似,都是一次处理一个请求,没有并发性。希望看到Bref的演示,了解如何使用Bref部署函数。Bref的应用程序结构和配置语法与Serverless Framework类似。询问Bref是否支持LambdaLift模式,以便将现有的PHP Web框架运行在Lambda函数中。使用Bref需要重新构建PHP应用程序,以适应其函数结构。使用Bref需要将PHP应用程序结构调整为包含`index.php`文件和其他PHP文件。比较Bref和Laravel Vapor的区别。询问在使用Bref运行单体应用时,如何进行可观察性监控和调试。目前PHP的无服务器可观察性工具不如Node.js完善。Bref的冷启动时间取决于应用大小和配置。比较Bref和Laravel Vapor在使用其他AWS服务方面的区别。许多公司使用Bref只是为了在云端运行PHP应用程序,而不是构建云原生应用程序。

Deep Dive

Chapters
Matthieu Napoli introduces Bref, a PHP framework for serverless applications. He explains how Bref leverages custom runtimes to enable PHP execution within Lambda, simplifying deployment for PHP developers and abstracting away Node.js dependencies.
  • Bref is a PHP framework designed for building serverless applications on AWS Lambda.
  • It utilizes custom runtimes, allowing PHP execution within Lambda.
  • Bref simplifies deployment for PHP developers, abstracting away Node.js dependencies.
  • Bref offers a similar configuration experience to the Serverless Framework.

Shownotes Transcript

Thank you to Momento for supporting this episode. Momento's real-time data platform empowers developers to build innovative products faster and more reliably than ever before. Visit gomomento.co/theburningmonk) for more information.In this episode, I spoke with Matthieu Napoli about the Bref framework for developing serverless applications in PHP - how it works, why PHP and how it compares with Laravel Vapor.This episode includes a short demo of Bref, if you want to see the demo in action, then check out the video version on YouTube here).Links from the episode:

  • Bref framework)

Opening theme song:Cheery Monday by Kevin MacLeodLink: https://incompetech.filmmusic.io/song/3495-cheery-mondayLicense: http://creativecommons.org/licenses/by/4.)