search
HomeBackend DevelopmentPHP TutorialHow to run PHP on AWS ServerLess architecture ? Part What&#s serverless?

AWS의 대표적인 서버리스 서비스인 Lambda를 사용하면 다양한 런타임에서 코드를 실행할 수 있습니다. 그러나 공식 제품 설명에는 PHP가 명시적으로 나와 있지 않습니다. Lambdas에서 PHP 코드를 실행할 수 없다는 뜻인가요? 아니요, 그렇지 않습니다!

이 시리즈(AWS 사용자 그룹 Poitiers와의 강연에서 파생됨)에서는 서버리스가 무엇인지, PHP(선호하는 언어인 경우)를 Lambda에서 실행하는 방법에 대해 논의하겠습니다.

서버리스란 무엇입니까?

서버리스는 클라우드 제공업체가 고객의 워크로드에 할당된 리소스를 동적으로 확장하는 동시에 물리적 인프라(서버, 전력 냉각)뿐만 아니라 실행 런타임(패칭, ..)까지 관리하는 호스팅 패러다임입니다.

How to run PHP on AWS ServerLess architecture ? Part  What

엄격한 의미에서 모든 요청에 ​​대해 컴퓨팅이 할당되어 '0으로 축소' 가격 책정 모델(리소스는 시간별로 지불되지 않고 실제 수요에 비례하여만 지불됨)로 이어지는 동시에 기본 제공되는 최고 수준을 제공합니다. -가용성.

이는 클라우드의 다른 이점에 추가되며, 주로 모든 것이 API와 함께 제공되어 자동화가 가능하다는 사실입니다.

이러한 이점이 합쳐져 사실상 무료 기능 분기 임시 환경을 확보할 수 있어 개발자 생산성과 리드 타임이 향상됩니다.

How to run PHP on AWS ServerLess architecture ? Part  What

서버리스는 컴퓨팅에만 국한되지 않습니다!

서버리스 생태계에는 다양한 솔루션이 있습니다. 2014년에 서버리스 컴퓨팅(Lambda)이 등장했을 때 관리형 대기열(SQS)은 10년, S3는 8년 동안 존재했습니다.

How to run PHP on AWS ServerLess architecture ? Part  What

위 슬라이드에서 Aurora는 0으로 확장되지 않기 때문에 엄격한 서버리스 정의와 일치하지 않습니다(v1은 0으로 확장되지만 시작하는 데 몇 분 정도 걸릴 수 있음, v2의 경우 데이터베이스가 쿼리를 제공할 수 있도록 작성자 및 리더 인스턴스 모두에 최소 0.5 ACU가 있어야 합니다.

아래에서는 서버리스 서비스만 포함하는 웹 애플리케이션을 호스팅하기 위한 일반적인 아키텍처를 확인할 수 있습니다. 제한된 수의 사용자에 대해 이러한 애플리케이션을 호스팅하는 데 드는 비용은 연간 1달러 미만일 수 있습니다.

How to run PHP on AWS ServerLess architecture ? Part  What

서버리스는 마이크로서비스에만 해당되나요?

그렇고..아니요. 이는 마이크로서비스를 염두에 두고 설계되었지만 여전히 모놀리식 아키텍처를 배포할 수 있습니다(새 환경이 시작될 때마다 장시간 실행되는 시작 시퀀스가 ​​없는 한).

How to run PHP on AWS ServerLess architecture ? Part  What

마이크로서비스의 일반적인 문제를 해결하기 위한 서버리스 옵션: 오케스트레이션 및 안무

마이크로서비스 아키텍처를 사용하면 애플리케이션 구성 요소 간의 결합을 줄일 수 있습니다(다른 언어 사용, 비동기 패턴을 통해, 인프라 수준 결합을 제거하여 확장성 향상).

그러나 단일 목적 기능이 여러 개 있는 경우 비즈니스 로직을 구현하려면 기능 간의 조정이 필요할 수 있습니다. 이러한 코디네이션은 두 가지 기본 패턴을 사용하여 구현할 수 있습니다.

  • 오케스트레이션: 이 패턴에서는 명령형 방식으로 함수 호출을 제어합니다. 이는 단일 서비스 팀이 기능을 제공하는 경우 비즈니스 도메인 에 자주 사용됩니다. 이에 대한 서버리스 접근 방식은 워크플로/상태 머신인 AWS StepFunction입니다. 여기 StepFunction을 사용하여 Lambda 함수를 조정하는 방법에 대한 훌륭한 튜토리얼이 있습니다.
  • 안무: 이 패턴은 매우 제한된 결합을 유지하기 위해 별도의 서비스 팀이 있는 교차 비즈니스 도메인 시나리오에서 더 관련성이 높습니다. 이벤트 버스를 사용하면 애플리케이션이 이벤트를 푸시하고 이벤트를 구독할 수 있습니다. 여러 소비자가 동일한 이벤트를 구독할 수 있으며 각 소비자는 필요한 모든 이벤트를 필터링할 수 있습니다. 이를 위한 핵심 AWS 서비스는 EventBridge입니다. 여기에 제가 쓴 블로그 게시물이 있을 것입니다.

람다 알아보기

Lambda는 AWS의 Function-as-a-Service 솔루션입니다. Lambda를 사용하면 인스턴스 배포와 OS 또는 런타임 패치에 대해 걱정할 필요 없이 코드를 배포하고 즉각적인 고가용성과 확장성을 얻을 수 있습니다.

Lambda는 동기 호출(API 게이트웨이, Application Load Balancer 또는 Lambda 함수 URL을 통해) 또는 비동기 호출(AWS 생성 또는 사용자 생성 이벤트에 응답)과 함께 사용할 수 있습니다.

When you deploy a Lambda you chose how much memory it needs to run. Allocated CPU is proportional. You then pay based on the number of milliseconds used. For instance a 128Mb Lambda costs 1.7*10^-9$/ms. That's 164 hours of compute before you spend your first dollar.

How to run PHP on AWS ServerLess architecture ? Part  What

And Lambda scales. Fast. Much faster than anything else. No more 429s (or 500 if you're workload is not well protected) errors due to high traffic variation.

How to run PHP on AWS ServerLess architecture ? Part  What

Solving the main challenge with LambdaLiths: cold starts

Lambda execution environments process only one single request at a given time, and are re-used for subsequent requests. That means that, for a Lambda function to scale, or when a Lambda function hasn't been invoked for a while, Lambda will have to start a new execution environment : that's a cold start.

If cold starts are detrimental to your application (again, that's probably better that all traffic being slow or hitting 429s), then there are a few options. AWS has a nice article about using Lambda warmers or setting provisioned concurrency to address it. In addition to those, for Java users, Lambda SnapStart features makes it possible to deliver good cold start performance, by snapshotting the microVM after the JVM inits.

What about PHP support?

The official product FAQ states it "natively supports Java, Go, PowerShell, Node.js, C#, Python, and Ruby code, and provides a Runtime API which allows you to use any additional programming languages to author your functions."

In the next blog posts in this series, we'll explain how you can run PHP on Lambda leveraging two distinct frameworks, Bref and the Lambda Web Adapter, and compare the possibilities offered by each of them.

The above is the detailed content of How to run PHP on AWS ServerLess architecture ? Part What&#s serverless?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools