Recent Posts


PHP and Amazon Lambda


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

I did another quick survey of what’s state of the art for PHP and Amazon’s Lambda (i.e. Serverless, i.e. Amazon will run a function for you in the cloud that can respond to HTTP requests and interact with Amazon’s various services, getting you out of the sys-admin business). One project I see cropping up in my various feeds is Bref. I wondered how they solved the whole “Amazon doesn’t support PHP in Lambda” thing.

To run PHP we must add the PHP binary in the lambda and have, for example, Javascript execute it.

Heavy that’s the most PHP thing I’ve read in a while Sigh. The article does go on to talk about the obvious problem (spinning up a new PHP CLI process to handle each request in real time, like we’re in CGI caveperson days), and that it comes with a 20ms performance penatly. I’d be curious to learn more about how well the Lambda function handles real-world web loads, as all my frozen caveman instincts say spinning up a process is expensive.

Weird, typical PHP, workarounds asside, using a framework like Bref is the way to go if you want to experiment with PHP in Lambda. While Amazon’s limitations may make the underlying implementation a bit janky right now, picking a framework means you can just write your PHP code. If Amazon ever gets around to providing real PHP Lambda support the framework authors can just update what their framework’s doing behind the scenes and your stuff should just run. Abstraction remains regeant.

Copyright © Alan Storm 1975 – 2022 All Rights Reserved

Originally Posted: 1st November 2018