5 ms·
For the curious here is how it works (this is all setup for you automatically when you type lambdaphp deploy): - Your requests are sent to Amazon API Gateway
by superasn 9y ago
For the curious here is how it works (this is all setup for you automatically when you type lambdaphp deploy):
- Your requests are sent to Amazon API Gateway
- AWS API Gateway invokes the Lambda function (pretty standard stuff)
- There is a NodeJS server running on Lambda that accepts incoming connections
- If the request is for a static file, it just serves it directly.
- If it is a php file, it sets up the environment vars ($_GET, $_POST, etc) and loads php-cgi and pipes the request to that and captures the output
- There is a wrapper script in between that creates a File IO wrapper to intercept any file IO and writes them to S3
- Similarly there is another wrapper to intercept requests to $_SESSION that are written to dynamodb
- It also loads the composer autoloader so it is possible to load any modules from the vendor directory
- deleted 9y ago[deleted]
- krapp 9y agoWhy is a NodeJS dependency necessary? PHP can handle and route requests just fine. Modern PHP even comes with its own server.
- superasn 9y agoIt's because Aws Lambda doesn't support PHP natively just yet[1]. Maybe if anyone from Amazon is reading this, please add support for PHP in Lambda too. It's still quite relevant and useful to a lot of users. [1] https://aws.amazon.com/lambda/faqs/ https://aws.amazon.com/lambda/faqs/
- joecot 9y agoAWS Lambda doesn't support php natively currently. It came out with Node support, and has since added Python, Java, and C#. Of them Node generally has the fastest startup time, so if you want to run an unsupported language (like PHP), you build a binary for that language, and then write a small node script to call it and handle the input and output.
- sreque 9y agoEvery measurement I have made of startup time puts Python 2.7 at about half the startup time of Node.js.
- pritambarhate 9y agoNow that Go is also supported it would be interesting to know what kind of start up time it has.
- tracker1 9y agoas sreque mentions, Python is a bit faster than node. Though both are much faster than the other options.
- Can_Not 9y agoLamdba doesn't support PHP natively, so one of the natively supported options has to be used to bootstrap it.