After the official announcement of PHP Layer for AWS Lambda by Stackery, we did not find any benchmark or proof of a PHP application running properly on AWS Lambda. Matthieu Napoli have just confirmed this “Stackery’s bootstrap file is very buggy and WIP, this first version is not usable at all, I don’t know what is planned there”.

Matthieu managed to compile and publish my own PHP 7.2 runtime, with all the extensions currently provided by Bref. Then explored writing another bootstrap from scratch that does not use/require pcntl and forks.

It’s an interesting opportunity especially that Stackery are not recommending usage of their runtime in production environment, it’s even unusable.

At this stage Matthieu is exploring different scenario to implement the bootstrap file :

  • Scenario A : The bootstrap starts similarly to what can be done with ReactPHP/Amp/Aerys… and run the PHP code in the same process as the bootstrap
  • Scenario B : Similarly to PHP-FPM, The bootstrap starts a sub-process (exec) every time an event needs to be processed.
  • Scenario C : Just like B except bootstrap does not handle events: it immediately executes a sub-process. The PHP sub-process will call the integration HTTP API and wait for an event. That means that we can run code before waiting for an event.
  • Scenario D : Instead of creating new processes, the bootstrap process is forked. Which mean the app would bootstrap once in total, but still there is no shared state between events.

There are few benchmarks for each scenario (Finally!) :

  • scenario A: 6ms without a framework (Slim framework, didn’t try Symfony yet)
  • scenario B: nothing yet.
  • scenario C: 95ms for Symfony, 75ms without a framework.
  • scenario D: 50ms for Symfony, 17ms for Slim, 13ms without a framework.

We cannot decide yet which alternative is better and there could be other better options, but I think it’s very interesting open discussion especially if you know very well PHP-FPM and PHP internals :

Updates 3/12/2018 : Matthieu posted benchmarks in a github repository, overall the first results are hot : “PHP can run twice as fast as before! And even better: with React/Amp/Swoole style Symfony can run in less than 10ms per request! So promising!”

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here