مرور زمان اجرای Lambda1:07
and a communication channel between it and the Lambda service. Inside the container, the execution environment starts multiple processes to run the function runtime, code, and any extensions. We will not be looking into extensions in this part of the series. Our main focus will be the runtime environment itself. This runtime integrates with the runtime ABI to retrieve invocation requests and report success and errors. Now, let's take a look at the execution environment lifecycle, which includes three phases, initialization,
Lambda Lifecycle Phases1:41
Now, let's take a look at the execution environment lifecycle, which includes three phases, initialization, invocations, and shutdown. During initialization, Lambda creates the environment with the configured resources and downloads the code. It bootstraps the Lambda runtime and runs the function's initialization code. In our case, the initialization code is the vapor runtime. We will look into that in a bit. Now, for the invocations phase, Lambda waits for invocation requests.
Vapor Runtime Initialization3:08
any files in the temp directory, and any background processes running. Now, let's zoom into the vapor runtime initialization. When you run the vapor deploy command, vapor injects some files into your application before uploading it to Lambda. These files are responsible for preparing the environment for the Laravel application to run. Things like loading composer autoloader, decrypting environment files, moving storage directory to the temp storage directory,
HTTP Handler with PHP-FPM3:35
decrypting environment files, moving storage directory to the temp storage directory, and caching configuration files. For the HTTP function, though, there is one additional task that is performed, which is starting PHP FPM and configuring it to listen on a specific Unix socket. Vapor later proxies any invocation requests to PHP FPM to handle, and then sends the response back to the Lambda runtime API. That way, every HTTP request will be handled using a new child process created by FPM.
CLI Invocations per Request4:07
That way, every HTTP request will be handled using a new child process created by FPM. No memory sharing between HTTP requests, which is what most people expect from a PHP web application. For the CLI handler, a new process that runs the artisan command is executed on every invocation. So similar to handling web requests, separate processes for each invocation. The only exception here is the queue handler. In this handler, the same application instance
Queue Handler Reuses Instance4:38
The only exception here is the queue handler. In this handler, the same application instance is created on initialization and is used to handle all incoming invocations. I hope by now you understand how your code runs inside the Vapor runtime and the Lambda execution environment.
