The secret behind FrankenPHP: Will it revolutionize PHP?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we're going to play with Franken PHP and see if it might actually change how we deploy PHP applications we're going to see what it looks like to use Franken PHP in just a second but let's see what Franken PHP is Right a modern PHP app server written in go Franken PHP is mainly concerned about how it serves PHP applications so it's going to use go the go thing it's using is a web server that web server is caddy cadd is actually a pretty popular web server written and go how does Franken PHP actually use who go that's a good question caddy it turns out has a modular system and this is a caddy module so what happens is caddy receives a web request from the internet and runs this Franken PHP module and the Franken PHP module does all sorts of crazy stuff like uh a c based thread pool all this good stuff it spins up PHP processes with a lot of concurrency right so it can actually handle a bunch of requests at the same time um it compiles down with the thread safe version of PHP it does all sorts of fancy stuff for us and all we need need to care about is that it's going to run our application which is great so um it native support for hp1 2 and three it creates Sr uh SSL certificates for us automatically these are actually all features of caddy it's not specific to Franken so that's pretty neat um there's worker mode worker mode is just like Lal octane right so L octane isn't yet supported but will be soon uh but that's all worker mode is in other words it loads your framework once into memory and then just keep setting request to that same uh instance of your application it does not spin up a new instance of your application for every new web request unlike you know PHP fpm or actually Franken which does normally without worker mode okay so let's see what it actually looks like to use this I have a PHP application here right so if we do PHP Artis and serve I can go ahead and open this in a web browser here and if we load it in our web browser here we'll see at the bottom the sappy sappy is the server application programming interface that is a thing that sits between your web server and your application right so PHP fpm apache's mod PHP uh sorry um what else uh C server right when we just run PHP artist and serve and now Franken PHP right so if I go ahead and run Franken PHP to load our same website here the sappy is Franken PHP right he uh the person who created Franken created their own sappy this thing that sits between um your PHP application code and the web server right what is actually the benefit of this to me the biggest benefit of Franken PHP is the ability to bundle up your code into one thing and ship that anywhere sort of like goang but um I didn't show you actually how it looks like to run this thing so the easiest way to run this thing is actually in a Docker container um it actually likes to be in Docker the best you don't need Ducker to run this but you will have the easiest time running it in a Ducker container or using a Ducker container to build a binary and running that binary on your Linux server somewhere not in a container um you can do all that stuff outside of containers too it's just a little easier because it's wrapped up in a nice package for us this way so we're going to do Docker run remove this when I'm done with this uh container share my application right this is a laral app in the Franken ised directory here so put that into the Container in the right place um use port 443 I'm not even going to bother the port 80 because this creates an SSL certificate for you automatically even if you're at Local Host um use you know the container image that Franken PHP created and uh I don't want this command I just want no command and that's going to spin up a web server for us so this is a bunch of structured logging output it's the result of caddy doing its thing and also the Franken PHP module that runs inside of caddy I can go ahead to Local Host with https load this page up and um the connection is not private because it created a uh self-signed SSL certificate so we can still visit this website yes I want to visit the website and it's loaded okay so down here we see this Happ Franken PHP again and that's what it looks like to run a lville application in Franken PHP it's just this one Docker command uh which is neat that's fine let's actually see what it looks like to package up our laral application into one binary that we can ship anywhere even if that anywhere does not have PHP or anything like that installed in it this is what I think is really gamechanging about Franken PHP we can package up our application into one neat little thing and just ship it off to any server which makes deployments a lot easier and simpler okay so I mentioned we need to use stalker for this and we uh don't need to but I'm going to cuz it's the easiest way to do it so I'm going to create this file called Static build a Docker file and in this Docker file I'm going to uh steal directly from freen PHP stocks a thing to put in here that's going to build our uh application into one little binary then we copy that binary out of the resulting container or image that we create the docker image and then we can just run that anywhere we want like on a Linux server or something okay and this is the content of that Docker file it's the static Builder Docker image that Franken PHP provides it's on amd64 servers right now uh not arm 64 so this might not work on your Mac or your M1 M2 M3 Macs uh I'm not actually sure you should give it a try and then we can just run the stuff to create our application and bundle it into one little binary right that's the build static. sh repos um bash script that runs in the Franken PHP repository and we can see we can set some stuff like PHP extensions I only have a few here but if I remove this it's actually going to build in like almost all the PHP extensions you might think of in fact if we head to their repository find the uh build static bash script static where are you build static. sh we can see PHP extensions if it's not defined if it's empty that's what Das Z means then it's going to build in these Extensions by default if we're on our Mac OS we build some of these otherwise we build some of these and I think the only difference is it just doesn't have post gray by default on Mech for some reason I don't know I could read this skub issue I'm not going to all right so let's head back over here and I think I can just go ahead and run this now I'm running this relative to my uh Lille application right so it's going to copy in my lville application code files here and this is just for local Dev but in reality you'd want like your production. EMV file and all that good stuff so uh let's see let's do Docker run and how do I run this thing so I'm going to say this I'm going to set a variable the variable is going to name this image static app and then I'm going to copy and paste from over here my notes we'll do Docker build- T app name like static app and using the static build docker file in my current directory and this is just going to ahead and build our application into uh the resulting image this Docker image here okay and that is finished this took like I think about 30 seconds after Ducker finally pulled down the docker image so it's actually a pretty quick process now there is a zany command we need to copy this file out of the resulting Docker image what this thing is doing is doing the docker copy command which can help you copy a file from a uh running container onto your host's computer right so we're going to get this onto our Mac OS computer out of that Docker image so it's going to create which is just going to create a container not just from the docker image it's going to create a container it's not going to run it but just create it it's going to name it static app Temp and it's going to create our app image here um the image we just created is named app image and then from that container it's going to copy this file Franken uh PHP lunux x64 64 whatever I can't talk it's going to name it my app and it's going to place that onto my Mac OS host here and then it's going to remove the thing we just created uh because it doesn't need it anymore okay so let's go ahead and do this and now we have a directory or a file here named my app and we can run that now I can't actually run that directly like this um because I'm on a Mac and this was built for Linux uh so what I can do is actually fake it Pretend We're on a Linux computer and I'll just do that through Docker again because we have it here so I'm going to do uh remove DV no I'm not going to share anything I'm going to do Port 443 in this container Port 443 auntu 2204 okay so I'm spinning up an instance of auntu 2204 this means it will not have PHP installed on it it'll be nothing but a base uh virtual machine which in this case is actually a Docker image of auntu and it has nothing installed on it at all right it's just aunu and um actually you know what I'm going to share a thing I'm going to share in my current directory um the file my app into where do we want to put this I'm going to put SL serve my app inside of this stalker container and then I'm going to run I'll just run bash here oh I totally did this wrong bash it I need that- it flag so we're actually attached to the stalker image and we can do stuff in it okay so we're in the serve directory PHP is not installed there's no uh web server nothing installed on this uh auntu container at all so let's go ahead and run my app we'll do PHP server and we're going to add domain Local Host here because that tells caddy to create an assell certificate for Local Host automatically and that will run it here okay so it's done the TLs stuff because we used that flag uh to give it a host name and since that's running at Port 443 we should be able to load that up here uh let's do htps Local Host we get our usual connection is not private and it works and we in the sappy Franken PHP so uh what what have we done here I have created this little binary my app I um put our application into it it has caddy in it right air web server so it's a self-contained binary that we can ship to any Linux server or virtual machine Docker container in this case and run it right so it's actually just like shipping a goaling program where you compile your goaling app and it becomes a self-contained binary you can ship anywhere at all and we get the same benefit with Franken PHP right we can build our lell application into this little thing and just ship it off uh to wherever we want to run it it can be in a container it can be in a Linux server somewhere uh you can build it from EOS if you want to to but you know typically uh in production you'll probably be running a Linux server right and let's see how big is this thing it's 168 megabytes which is really not too bad uh it includes a goaling program it includes your larval app with your vendor directory your uh I don't have any node modules in this case that'll probably blow it up even bigger but hopefully you don't even need those for production because those um are only used for building your static assets right so what we can do here is build up a process where on push to production to deploy our code we get our uh non-ev dependencies from composer we build our static assets and then we get our production. EMV file into one location run this build process so we get our application built and then we can ship the result this my app binary or you can name it whatever you want we can ship that into production by just kind of like swapping out the binary which binary is running so we don't even need to you know do all this stuff on our server like Lal Forge likes to do a quick um what does it call it a quick deploy where it does a composer you know pull and all that stuff and it's not really zero downtime at all or you might use envoyer which does the same thing but runs it and does like the Sim link dance to create a zero downtime deployment but it's still running all this stuff on your production server here we can actually just ship a binary and just put that wherever we want and we don't need any stuff installed on the server at all right no PHP no web server all that stuff we just have it all contained into this one file I think that's pretty revolutionary for PHP right because that's something you only get in other languages like go and H this just sounds so awesome to me such a better deployment story now are there downsides to this I don't know you know it's not engin X engine X is written in C it's super performant caddy is not as fast but can still handle a lot of traffic goang is still performant right people use goang based web servers all the time in production like traffic and all that stuff where they're routing requests and making micros services and all that stuff is highly used in production so I wouldn't be scared of it from that point of view but you know it is technically a little less performant I just like it doesn't matter for most of our applications caddy does a lot of cool stuff the logging is better um the let's just let's check out franken's site there's so much stuff right it gives us structured logging um Prometheus metrics which are really nice for monitoring your site graceful reloads HTTP 3 and gzip and all that stuff is supported worker mode when uh Lille octane support finally hits worker mode is supported so that's great and um it's it's easy you know it's kind of just works all right so I think this is really cool I'm going to try using this in productions for myself but you have any thoughts ideas comments questions if you think I did something stupid if you think I missed some important points please let me know in the comments jump in there let me know what you think
Info
Channel: Chris Fidao
Views: 35,511
Rating: undefined out of 5
Keywords: servers, php, laravel, frankenphp, docker, golang, caddy, caddyserver
Id: q6FQaaFZVy4
Channel Id: undefined
Length: 12min 39sec (759 seconds)
Published: Tue Dec 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.