12 ms·
FrankenPHP: Modern PHP App Server
- alberth 2y agoIs this just Caddy + PHP?
- WillyOnWheels 2y agoIt's basically a Caddy plugin that works as a drop in replacement for php-fpm, created by https://news.ycombinator.com/threads?id=kdunglas https://news.ycombinator.com/threads?id=kdunglas
- francislavoie 2y agoI wouldn't really call it a drop-in replacement for php-fpm. It's more like emulating the way Apache+PHP was run traditionally, i.e. PHP is closer to the webserver instead of being a separate piece as it is with php-fpm (and needing fastcgi as protocol glue). But yes, from a practical standpoint, your PHP apps should _just work_ if you run it with this instead of php-fpm, provided that you aren't doing anything weird. If you're using a modern PHP framework (e.g. Laravel, Symfony) then you can use FrankenPHP's worker mode which is a huge boost in performance by keeping workers running which have the framework already warmed up and ready to accept requests right away, instead of having to boot the framework on every request.
- CodeCompost 2y agoWhat is the Go part? It's a PHP interpreter or is PHP still doing all the work?
- alberth 2y agoThe web server (Caddy) is written in Go.
- francislavoie 2y agoGo is acting as the process manager for PHP (either keeping a pool of workers running, or directly invoking PHP via CGO), and as the HTTP/HTTPS server (Caddy, obviously), ACME automation, etc. It's not a "PHP interpreter", it's literally PHP itself (written in C, compiled in with CGO).
- dang 2y agoRelated: Show HN: FrankenPHP, an app server for PHP written in Go - https://news.ycombinator.com/item?id=33205282 https://news.ycombinator.com/item?id=33205282 - Oct 2022 (83 comments)
- gnabgib 2y agoAnd Show HN: Package PHP apps as standalone, self-executable binaries (29 points, 5 months ago, 7 comments) :D [0]: https://news.ycombinator.com/item?id=38569637 https://news.ycombinator.com/item?id=38569637
- infogulch 2y agoAlso, on the homepage today, which may have been inspiration: Caddy 2.8 - https://news.ycombinator.com/item?id=40517576 https://news.ycombinator.com/item?id=40517576
- deleted 2y ago[deleted]
- notpushkin 2y ago> Copy your PHP files in the document root, that’s all! sigh
- c0wb0yc0d3r 2y agoHow would you prefer it to work?
- darylteo 2y agoIf I understand the top-poster's issue correctly: https://frankenphp.dev/docs/ https://frankenphp.dev/docs/ docker run -v $PWD:/app/public \ -p 80:80 -p 443:443 -p 443:443/udp \ dunglas/frankenphp This mounts the current working directory into "public". Meaning, all .git, .env etc. will be publicly accessible. Better form would be to mount a $PWD/src directory instead. The documentation needs to be updated better for newbies. Generally ill-advised. Documentation just needs better updating or warnings. Very dangerous to inexperienced devs. In comparison the Laravel integration, it instructs the following: https://frankenphp.dev/docs/laravel/ https://frankenphp.dev/docs/laravel/ docker run -p 80:80 -p 443:443 -p 443:443/udp -v $PWD:/app dunglas/frankenphp While all the sensitive files are mounted in, they have to be to function properly. In this case, they're mounted to a more secure context.
- withinboredom 2y agoIt literally says “copy your PHP files” note the PHP part. It doesn’t say copy all your secrets and git history too.
- huimang 2y agoIf you run the above docker command, which is directly from the docs, it copies everything inside of your current working directory. Not just PHP files.
- withinboredom 2y ago
- jslaby 2y agoLong time C# dev, now I primarily code in PHP8 which is a great language to quickly get things done. This is the kind of direction the language needs to go in, instead of the older LAMP which can require somewhat complex Apache configuration.
- hparadiz 2y agoPHP dev of 18 years here. Use nginx with php-fpm. It takes 5 minutes to configure. Edit: I'm gonna give this thing a try too but I've never had any bottlenecks with either nginx or Apache. They both take a few minutes to get going at most.
- lordofgibbons 2y ago>It takes 5 minutes to configure Is that because you have 18 years of experience, or would it be as easy for a new developer?
- hparadiz 2y agoI just have the right config for both Apache2 and nginx from hundreds of sites. The config itself is only 50 lines. You can find a good one and stick with it.
- troupo 2y agoYup. The process of finding alone will take more than 5 minutes. And is likely to not work for your particular circumstance.
- donatj 2y agoI think it would be roughly that easy for anyone with basic nginx experience. Nginx includes a php fast-cgi snippet that you just `include` from your server block. It really is very easy.
- chrisandchris 2y agoI was a long-time PHP dev and then moved on to C#. I was close to writing this nginx/fpm setup lookss very complex compared to "dotnet run". But then I remembered, in ASP.NET you have a Program with 50 lines of code that must have an exact order, otherwise thinks work except they don't. So I would say, knowing these two languages, PHP really is that easy to setup.
- geenat 2y agohttps://github.com/dunglas/frankenphp/discussions/294 https://github.com/dunglas/frankenphp/discussions/294 Has perf issues. Otherwise it's a really promising project.
- withinboredom 2y agoIf I could reproduce it, I’d happily take two weeks off from work and fix it. Nobody has mentioned how to reproduce it.
- harrisonjackson 2y agoI haven't done any php development in maybe 10 years but this landing page almost got me to spin up a hello world. I like the elephant frankenstein character - goofy and ugly/cute. Design, color scheme, copy, and animations are clean :chefkiss: The value prop is well highlighted - at least for someone that's been out of php dev for a while. This seems like a nice way to bootstrap something small. Getting started code snippet makes it seem quick and easy.
- zer00eyz 2y agoI moved from PHP to Golang a bit over a decade ago... Because binary deploys are the bees knees. I dont want 8 containers isolating a bunch of bad software or worse messed up dependency's (looking at you python, maybe some ruby and node code as well). Because rather than releasing installable software you packaged up "works for me" and shipped it to the world. I might play with this out of nostalgia but not so sure that I want these sorts of things in my production environment any more.
- francislavoie 2y agoThis is PHP running inside a Go server, btw. Compiled with CGO. One binary, one process.
- zer00eyz 2y agoWow the PHP is going to magically get into the binary? /s Yes I could build this with c-go + the PHP and statically link everything (and there might need to be a bit of prayer involved...) ... or I could just write GO and accomplish all the same things with fewer steps. That knotted up mess is why containers are popular.
- francislavoie 2y agoWell, FrankenPHP avoids that prayer, cause it's already done for you lmao But obviously the point of using PHP is for its ecosystem, frameworks etc. Go is still missing a lot of that, the Go community has a weird aversion to frameworks.
- chuckreynolds 2y agooooh interesting. been a min since i've needed a php + WP setup but... not bad.
- CoolCold 2y agoI've tried to do Wordpress benchmark under FrankenPHP and under Apache's Mod-PHP - I couldn't see evidence of winning for FPHP. Have not dug deep enough though and test was in Docker, not on normal setup. Wordpress was basically in default setup - no heavy themes or anything of this sort, not very realistic case too. Still want to repeat test and understand it better.
- mhitza 2y agoMaybe you're using that name because you're accustomed to, but as a standard you should be using proxy_fcgi with Apache. Should squeeze out a bit of extra memory out of Apache and leave room for more PHP requests.
- CoolCold 2y agoNot sure where you take this "standard" from - AFAIR, it was mod_php since ~ 2004-2005 and all that lovely mpm_prefork stuff. FastCGI and FPM came a bit later. > should be using proxy_fcgi with Apache I'd in general use Nginx instead of Apache, until .htaccess handling is needed - which is still a thing in shared hosting and around area mostly from my perspective - if you really care about "squeeze out a bit of extra memory" of course.
- mhitza 2y agoI take it as a standard because its the approach recommended above all others in the Apache wiki [1] and probably what distros will do at some point as well (RedHat family distros already do this if you don't explicitly opt-in to use mod_php). [1] https://cwiki.apache.org/confluence/plugins/servlet/mobile?contentId=115522403#content/view/115522403 https://cwiki.apache.org/confluence/plugins/servlet/mobile?c...
- CoolCold 2y agoThank you for clarification - makes a lot of sense what they state in that docs > Why you shouldn't use mod_php with the prefork mpm anymore > > mod_php is loaded into every httpd process all the time. Even when httpd is serving static/non php content, that memory is in use. > mod_php is not thread safe and forces you to stick with the prefork mpm (multi process, no threads), which is the slowest possible configuration I probably very biased here - I silently imply it's a Nginx in front of Apache in 99.9% cases - so serving static files and long-living connections is not a problem with mpm_prefork [for setups and system administration around me].
- NorwegianDude 2y agoI tried it and found it to be really slow, not even using my cores properly. Spent some time in the lacking docs and didn't figure it out... It says production ready with just a few commands and states 3,5 times the performance of fpm, but it's running at like 1 % of the performance of fpm for me. I also tried the executable, same issue. Was expecting at least 200K rps for hello world...
- geenat 2y agoWould appreciate sharing your experience so we can get this addressed: https://github.com/dunglas/frankenphp/discussions/294 https://github.com/dunglas/frankenphp/discussions/294 It's really awkward because Caddy by itself performs very well with PHP.
- deleted 2y ago[deleted]
- kdunglas 2y agoHi, FrankenPHP author here. We would very much appreciate a reproducer. According to most benchmarks, FrankenPHP is generally much faster (~3 times) than FPM when worker mode is enabled, but there are still some outliers, and we're working with PHP maintainers to fix them.
- sandreas 2y agoWhile I often use the PHP integrated webserver during development: php -S 0.0.0.0:8000 public/index.php it is single threaded, slow and therefore not made for production environments. FrankenPHP looks promising, while the issue with limited Cores / Threads[2] seems also to be a problem when using it in production. However, maybe I'll give it a go for my pure-todo[1] project and see, if it suffers the same problem. The docker image as base looks really promising. Thanks for sharing. 1: https://github.com/sandreas/pure-todo https://github.com/sandreas/pure-todo 2: https://github.com/dunglas/frankenphp/discussions/294 https://github.com/dunglas/frankenphp/discussions/294
- 20after4 2y ago>it is single threaded, slow and therefore not made for production environments. I'm pretty sure that this solves those specific issues (and more)
- lpapez 2y agoThe PHP built-in server is explicitly stated not for production use, and is intended for development purposes only. See the warning at the top of the page: https://www.php.net/manual/en/features.commandline.webserver.php https://www.php.net/manual/en/features.commandline.webserver... Not sure it's even fair to consider it for comparison in this context.
- sandreas 2y agoThat's what I meant. But tbh I don't think FrankenPHP is ready for Produktion yet, although it might geht there some day. Just wanted to mention that using PHP locally, for simple app development you don't need a full fledged nginx, Apache or caddy in all cases
- PetahNZ 2y agoYou can set PHP_CLI_SERVER_WORKERS to make it run multiple threads.
- sandreas 2y ago
- 63 2y agoInteresting for sure. My current setup is your basic nginx, fastcgi, php-fpm. I have some custom ngnix config though and I wouldn't want to have to switch web servers. I guess I could still use nginx as a reverse proxy and point it to this but then what's the point? I'll look into it for future projects where I really just need a simple php deployment, but for my needlessly complex project I'm already working on, I don't think it fits.
- pachico 2y agoI enjoy seeing this in the front page of HN. My feeling is that FPM and its share nothing arquitecture has been both the key of PHPs success many years ago but also its condemnation.
- mg 2y agodocker run -v $PWD:/app/public -p 443:443 \ dunglas/frankenphp If you want to build a docker container yourself that you can use to serve your app, then running these commands should do the trick to turn a fresh Debian into the container you need: apt install -y apache2 libapache2-mod-php cat << 'EOF' > /etc/apache2/sites-enabled/000-default.conf ServerName mysite.local <Directory /app/public> AllowOverride All </Directory> <VirtualHost *:80> DocumentRoot /app/public </VirtualHost> EOF Friends and I maintain a repo which shows how to go from zero to a running web application via popular languages and frameworks here: https://github.com/no-gravity/web_app_from_scratch https://github.com/no-gravity/web_app_from_scratch
- johnchristopher 2y agoUnless I am mistaken this won't work: does default apache 000-default.conf vhost redirect traffic from 443 to 80 ?
- mg 2y agoTo support SSL you would add a virtual host section like this: <VirtualHost *:443> ServerName mysite.local SSLEngine on SSLCertificateFile /path/to/cert SSLCertificateKeyFile /path/to/key DocumentRoot /app/public </VirtualHost> And either use a real cert or add a command to create a self signed one: openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key -out cert
- lnxg33k1 2y agoI started working a month ago for a company using mod_php, it's painful, every time you start xdebug, then after the debugging session, you need to restart apache, I started yesterday configuring apache2 to use php-fpm, but I was just wondering if it could work for us, at least in dev, this frankenphp, just can't find how to install php-exts in the docs
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- jumperabg 2y agoAre there any benefits on running WordPress on top of FrankenPHP?
- francislavoie 2y agoYou won't notice much performance benefit (because WordPress doesn't support worker mode yet), but it is simpler to run and deploy (single binary) and you get all the benefits of Caddy out of box too, like TLS automation.
- withinboredom 2y agoNot yet. It's possible when combined with some multi-site features of WordPress, an mu-plugin could enable worker mode with WordPress. Though, I'd have to contact my old employer (Automattic) to ask if they would be ok with me using an approach used on WordPress.com, which I'm fairly certain is a 'trade secret.'
- thomasfromcdnjs 2y agoIt would seem that this is more or less an alternative to Octane but I don't understand why there is documentation to also run Octane -> https://frankenphp.dev/docs/laravel/#laravel-octane/ https://frankenphp.dev/docs/laravel/#laravel-octane/ Why would you run both?
- francislavoie 2y agoIt's not an "alternative", FrankenPHP is one of the 3 available drivers for Octane. See the Laravel docs https://laravel.com/docs/11.x/octane https://laravel.com/docs/11.x/octane Octane is basically Laravel's branding for its "worker mode", i.e. running a long-running process which boots the framework and then processes requests, without needing to reboot the framework on every request.
- thomasfromcdnjs 2y agoThanks for the answer. So you would turn on Frankens worker mode to sit on top of Laravel Octanes workers? My understanding is that Franken keeps the app running so Laravel wouldn't need to restart anyway?
- francislavoie 2y agoNo, you use Octane to run FrankenPHP. Octane will download and run FrankenPHP for you. FrankenPHP is a program which has a webserver (Caddy) and PHP built-in, and worker mode allows it to run a pool of workers which have your Laravel app bootstrapped (all your service providers, middleware, controllers ready to go in memory) and then FrankenPHP feeds it requests as they come in.
- kuekacang 2y agoTo add, octane does a trick that, frow what i grasp from reading the source, it cap for a total of n request (200?) and kill the worker to preemptively free up ram
- 2y ago
- blixt 2y agoReminds me of that time 10 years ago when I tried to make Go more like PHP instead of the other way around: https://github.com/blixt/go-pher https://github.com/blixt/go-pher More seriously, happy to see worker mode in this server. PHP does come with several performance downsides, though I’m sure a lot of them have been worked around in the past decade. I don’t think I’d do PHP again though if I’m being honest.
- pseudosavant 2y agoThere seem to be a lot of us with this PHP sentiment. PHP is like a girlfriend you lived with that was easy going and super cool at first...but by the end she might have been trying to poison you. She's been to therapy since and doing really awesome, but how could you ever go back right? Like, I'm really happy for the (many) remaining PHP devs that it isn't the shitshow it got to be around PHP6. But it could never tempt me back. Deno, Django, Go, dotnet...plenty of other fish in the sea.
- zmxz 2y agoThere are claims this is faster. It's not. I used it, together with other "alternative" runtimes which are just PHP command line interface long running scripts with some sort of task distribution balancer in front. Just like PHP-FPM is. The apparent speedup comes from the fact it's not shared-nothing, meaning that objects from previous requests (and variables) are persisted and present in subsequent requests. This makes it work exactly like Node.js, removing the wonderful part of PHP which is that it automatically cleans up all the crap devs created and creates clean slate when next request is to be executed. All of these "alternative" runtimes are false positives, because they're quick for first few requests but get slower and slower for the subsequent ones. Then, the workers are killed and restarted (precisely what PHP-FPM does too). Since there's no new engine behind executing PHP, the only way FrankenPHP (and others) can yield any performance is when they're benchmarked against misconfigured PHP-FPM (opcache off, JIT off, persistent connections off). It's not my cup of tea. I like that there are attempts at doing <something> but turning PHP execution model into Node.js execution model isn't the way to go. I find it cheaper to throw a few bucks at stronger hardware compared to risking accurate execution to become flaky because shared-nothing is now unavailable.
- withinboredom 2y agoThe right answer, as always, is: "it depends." There's no definitive "faster" or "slower" anything and the claim is "up to" not "you will get." Some workloads won't see any benefits, others will. While your anecdata might be useful, it is just that, an anecdote.
- zmxz 2y agoIt doesn't even depend. The underlying engine that executes opcodes is the same. Minimal speedup from not having to execute several "new objectname" commands isn't even a drop in the sea when it comes to what servers do. I, for one, would love to be wrong about this and that FrankenPHP with all the other alternative runtimes actually brought benefits.
- withinboredom 2y ago
- oksteven 2y agoI have been looking for something like this for a while; it's great to see one now. My current approach is to use nginx container as a proxy to another container which run php-fpm, I don't think it's efficient enough. I'll try Frankenphp and see if it can do better.
- ThinkBeat 2y agoDoes this still require running Nginx as a reverse proxy in front of it?
- withinboredom 2y agoNo, and I'd recommend not doing so unless you need to. Caddy/FPHP supports https3 out of the box, and I don't think nginx does (at least the versions currently packaged in major distros).
- elitepleb 2y agothis runs caddy (another famous reverse proxy) for you
- ofrzeta 2y agoAlternatives are: - Roadrunner https://roadrunner.dev/ https://roadrunner.dev/ (also written in Go) - Swoole https://www.swoole.com/ https://www.swoole.com/ https://openswoole.com/ https://openswoole.com/ See https://laravel.com/docs/11.x/octane https://laravel.com/docs/11.x/octane for Laravel specific framework integration.
- francislavoie 2y agoIt's only an alternative if you're running a framework which also supports those (your PHP app has to be set up in a specific way for Roadrunner or Swoole to be usable). FrankenPHP has the advantage of working with _any_ PHP app (even WordPress) because it's just PHP, but compiled into a Go program with CGO. But it also has a worker mode which makes it behave similarly to those two.
- ofrzeta 2y agoAh, I didn't get that. Thanks for the clarification.
- rustatian-me 2y agoYou don't need any framework or specific web-server to use RoadRunner. RoadRunner can be used with any modern framework, or let's say naked, using only the PSR-7 (which is framework-agnostic) worker for HTTP, but: RR is not only HTTP, it is waaaay above that: Temporal.io support, various queue drivers, gRPC, TCP, KV, Native WebSockets/Broadcast support, distribute locks (without PHP extensions), etc. RR doesn't need to be somehow specifically set-up. Nothing special, download -> use :)
- francislavoie 2y agoPSR-7 is framework agnostic, but not all PHP apps are PSR-7 ready. E.g. WordPress. That's the distinction. You can't just point Roadrunner at any PHP script or legacy PHP app and expect it to just run, but you can with FrankenPHP.
- 2y ago
- timvdalen 2y agoWhat does it mean to get rid of PSR-7 in today's age? Do people really miss $_GET and $_POST?
- kdunglas 2y agoThis means that in addition to any PSR-7 implementation, you can run apps using HttpFoundation (Symfony, Laravel, Drupal, etc) and "legacy" code using superglobals without the need for an adapter.
- timvdalen 2y agoIn that case I think I'm missing the value prop here, doesn't that also hold for plain old php-fpm?
- lnxg33k1 2y agoCould you integrate the documentation, or point me where it is explained, how to add php extensions? Like xdebug, opcache, etc? If there is something like docker-php-ext-install? Please, thank you
- whalesalad 2y agoInterested to see how this fares on Tech Empower's benchmarks: https://www.techempower.com/benchmarks/#hw=ph&test=fortune§ion=data-r22&l=zik073-cn3 https://www.techempower.com/benchmarks/#hw=ph&test=fortune&s... At the moment it is at the bottom as a "did not complete"
- samuell 2y ago"Build standalone, self-executable and dependencies-free binaries for your PHP web applications, and command-line tools." I'm sold.