Home Backend Development PHP Tutorial How to run PHP on AWS ServerLess architecture ? Part What&#s serverless?

How to run PHP on AWS ServerLess architecture ? Part What&#s serverless?

Oct 07, 2024 pm 10:09 PM

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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles