DEV Community

Daniel, Petrica Andrei-Daniel
Daniel, Petrica Andrei-Daniel

Posted on • Originally published at danielpetrica.com

A Production-Ready Laravel Architecture with Traefik and FrankenPHP

Laravel is a very performant framework, but a standard architecture has one big flaw derived from how PHP works: It has to rebuild the entire framework on every single request.

Even with optimizations, this process still takes 40 to 60 ms on my machine with PHP 8.4. Luckily, for years, the PHP and Laravel worlds have had a solution that dramatically reduces this load time: Laravel Octane and FrankenPHP. The booting time for the Laravel framework can drop to just 4 to 6 ms per request. Incredible, isn't it?

Now, if you're new to Laravel Octane or FrankenPHP, you may wonder: How is this possible?

The simple answer is that the framework is kept in memory. After FrankenPHP starts, Laravel is always ready to serve requests without a full reboot. The real explanation is more complex and out of scope for this article. If you're curious, you can read the official Laravel Octane and FrankenPHP docs for a deeper dive.

read the full article at: DanielPetrica.com

Top comments (1)

Collapse
 
xwero profile image
david duymelinck

one big flaw derived from how PHP works: It has to rebuild the entire framework on every single request

It is not a PHP flaw. It is the way how script languages work. Python, Perl, Ruby, even Javascript have the same characteristic.

PHP tries to make the cold start as fast as possible by using OpCache and JIT.

The simple answer is that the framework is kept in memory.

All script languages use a server that keeps the process running. So keeping it in memory is not the real actor. There is not more complex than that.

If your summary already has flaws, I don't think it is worth to go to your website.