6 ms·
Show HN: FrankenPHP, an app server for PHP written in Go
- nonoesp 4y agoIt'd be great to see how a Laravel app could run on FrankenPHP and see if there are speed gains. My current setup is a DigitalOcean Droplet with Nginx and php-fpm.
- some_developer 4y agoTry Octane, it's the app server we were longing for.
- codegeek 4y agoI see a bit of C as well ? Also, do we need to use Docker ? I am very interested in trying but wanted to check. If it is Go, can I not just compile the binary and execute ?
- TheRealPomax 4y agoWhen do things ever "just compile"? I assume the Docker image is because this is a pre-alpha and the docker image ensures that no one needs to go through hours of dependency/config hell because the docker image is set up with everything necessary already, letting you focus on alpha-testing this and reporting bugs.
- calvinmorrison 4y agotypically I find CMake would do this, or Make, to verify dependencies. Coupled with a packaging system, like debian gives you, this is all pretty straightforward. I ran into this yesterday, and turns out I don't want to install docker just to build a program...
- TheRealPomax 4y agoRight, but there are as many setups as there are potential users, so even if Debian works, that doesn't mean other linux flavours will work as easily, or flavours of BSDs, and then also Macs, and even WSL, or even just plain old Windows. Having an "everyone gets the same thing, so no one wastes time on bootstrapping" solution is a perfect use-case for Docker. And then once the bugs have been found and fixed, and the code is production-ready, you can focus on documenting and scripting the setup procedures for the various operating systems.
- andirk 4y agoAs an aside, may I ask what people's opinion of running docker containers in prod is? The joke "But it works on my local--" "Then ship your local".
- francislavoie 4y agoThe big win of Docker for me is parity between dev and prod. I absolutely run on Docker in prod. It is not just a dev tool.
- tracker1 4y agoBeen using docker in prod for over 5 years now...
- badcppdev 4y agoI don't understand. I thought you needed different docker files for different architecture? x64 vs M1 chips?
- gocartStatue 4y agoOr Nix :)
- TheRealPomax 4y agoExcept of course in this case that's not what you'd be doing. You'd be installing Docker to help beta-test a program, not "just build a program". If you want to help an open source project succeed, having to install Docker is kind of a trivial cost. If you want to use this... probably not a good idea, it's extremely not ready for general use =)
- francislavoie 4y agoC is necessary because PHP is written in C. So CGO is used to interface with PHP directly from Go, from a Caddy plugin. Docker is definitely not necessary, but it is the easiest way to ship something that just works. Since you need a bunch of build dependencies to compile PHP, the installation steps are different for every distro to pull those in with whatever's your package manager.
- password4321 4y agoPHP in .NET: https://www.peachpie.io https://www.peachpie.io
- deleted 4y ago[deleted]
- NorwegianDude 4y agoNot really sure what the pros of this is. Simple to deploy in a docker image? Didn't know that was an issue. I guess performance also takes a hit, and that worker mode is a good amount slower than Swoole? Some benchmarks against mod_php, nginx+php-fpm and swoole would be nice.
- sica07 4y agoNot a benchmark but some helpful stats can be found in this slide: https://speakerdeck.com/dunglas/frankenphp-a-modern-app-server-for-php-written-in-go?slide=22 https://speakerdeck.com/dunglas/frankenphp-a-modern-app-serv...
- simlevesque 4y agoFélicitation ! Do you have any success story with this application server ?
- francislavoie 4y agoKinda early for that, isn't it? It's still in the experimental phase.
- seabrookmx 4y agoSo.. it's like gunicorn (pre-fork web server) but for PHP and built on top of Caddy? Looks neat!
- timw4mail 4y agoSo after looking at the slidedeck on the authors blog, I'm rather confused. How does FrankenPHP keep the code in memory if each request is in a separate memory space?
- kingkool68 4y agoSee Preloading which landed in PHP 7.4 https://stitcher.io/blog/preloading-in-php-74 https://stitcher.io/blog/preloading-in-php-74
- marcofatica 4y agoThey're probably using PHP's built in opcache or something they rolled themselves OPcache improves PHP performance by storing precompiled script bytecode in shared memory https://www.php.net/manual/en/intro.opcache.php https://www.php.net/manual/en/intro.opcache.php
- chx 4y agoopcache is definitely on https://github.com/dunglas/frankenphp/blob/f97f56d45a403342bb215208f664adab9e7e6013/Dockerfile.dev#L55 https://github.com/dunglas/frankenphp/blob/f97f56d45a403342b...
- green-salt 4y agoI'll have to try this out!
- nobleach 4y agoI've been watching how Go and Rust tooling has been finding its way into the JavaScript ecosystem. I've been out of the PHP realm for about 10 years but I did find RoadRunner for PHP at one point. That's also an app server written in Go I believe. I wonder how this compares.
- fideloper 4y agoMy understanding is RoadRunner is more like FrankenPHP's "worker mode" (RoadRunner only makes sense in context of Laravel Octane), where as FrankenPHP can run "normally" as well.
- jedisct1 4y agoDon't forget Zig, with Bun.
- nobleach 4y agoAh yes. I've had my eye on that as well!
- deleted 4y ago[deleted]
- chx 4y agoLooking at the forked PHP source https://github.com/php/php-src/compare/master...dunglas:php-src:frankenphp-8.2 https://github.com/php/php-src/compare/master...dunglas:php-... I do not expect compatibility issues.
- deleted 4y ago[deleted]
- tiffanyh 4y agoI might be missing the obvious but why would you add extra complexity to your infrastrucutre setup when PHP can be run natively from within caddy, apache, nginx via fastcgi.
- fideloper 4y agoRemoving php-fpm + nginx from a container sounds AMAZING to me. If I can just have one thing in a container (plus a code base), that would be a LOT simpler than: nginx, php-fpm, some init system, and the convoluted configuration needed to get logs out via Docker's logging mechanism.
- PlutoIsAPlanet 4y agoI've recently changed our nginx/php-fpm containers to caddy/php-fpm Caddy has a supervisor plugin, so can start php-fpm itself and the containers entrypoint can be Caddy, which achieves similar objectives here that Caddy becomes a PHP application server.
- francislavoie 4y agoFrankenPHP will perform better than php-fpm though, in worker mode, because it doesn't need to bootstrap fully on every request. In the conference slides, Kevin showed php-fpm had a 12ms request latency, whereas FrankenPHP had 3ms. But yes, the supervisor plugin is definitely nice to be able to wrap up Caddy + php-fpm in a single container. Makes shipping it easier, especially with the PHP code (because both Caddy and php-fpm need access to the code; Caddy so it can serve static files and check for the existence of PHP files, and php-fpm to actually run your code).
- mekster 4y agoSo, not for everyone, especially when you have to manage your own binary. No one can feel 0.01s faster load time and there will be a dozen more things to tune in your app than shave that tiny bit off.
- 0xbadcafebee 4y agoSo it's mod_php for Caddy, in reverse? The traditional idea is to build a plug-in for the parent webserver. By essentially "making a fork" of Caddy, if you want to add other plugins to Caddy and then incorporate them into FrankenPHP, it's a lot more work. If instead you ship a PHP plugin to Caddy, you can manage Caddy instead and mix and match different functionality in one place. But I guess it's heretical to suggest somebody use plugins in Go, if the whole idea is everything is a static binary.
- mike_d 4y agoEarly Hints breaks a lot of the common APIs (like FastCGI/FPM) where you are expected to have one request and one response. I don't know how Caddy specifically works, but I suspect that may be the reason for the fork.
- mholt 4y agoEarly Hints support was added to Caddy's proxy by Kevin Dunglas, the author of FrankenPHP. No fork required for Early Hints!
- mholt 4y agoI don't think this forks Caddy. Rather, it is a Caddy plugin: https://github.com/dunglas/frankenphp/blob/main/caddy/caddy.go https://github.com/dunglas/frankenphp/blob/main/caddy/caddy.... It uses mainline Caddy: https://github.com/dunglas/frankenphp/blob/main/caddy/go.mod https://github.com/dunglas/frankenphp/blob/main/caddy/go.mod
- deleted 4y ago[deleted]
- 0xbadcafebee 4y agoCan I use an officially released build of Caddy and have that official Caddy executable load FrankenPHP?
- 4y ago
- treahauet 4y agoCongratulations! This looks neat!
- k__ 4y agoPHP is already FrankenPerl, and Perl FrankenAwk? What happened to the times where some crazy person would simply slap together an interpreter and call it a language? Somehow, language creation got more and more sophisticated these days.
- mhd 4y agoReally? Aren't there a lot of slapped together LLVM frontends these days?
- deleted 4y ago[deleted]
- bdg 4y agoIn general I wish the "culture" of programmers would differentiate the "language" itself from the "things it is linked with" and "the ecosystem of available packages". We get a lot of pointless arguments where person 1 is talking about case 2, and another is thinking about case 3. PHP, Ruby, and Node all use things like cURL or the same PCRE regex lib, but I've seen uninformed or misguided arguments about "how Node is better than PHP at making HTTP requests because of axios", and not "I like Axios more than Guzzle3".
- jeffersonheard 4y agoIf this isn't pronounced Frankenphip I will be disappointed.
- pbowyer 4y agoGood. PHP-FPM needs a challenger as anyone who has tried to debug it or its pools knows. Or to tune it (so many modes, so many configuration options). Litespeed's PHP LSAPI [1] shows how good performance can be with other setups. It'll be great if FrankenPHP gets to the same state. 1. https://www.litespeedtech.com/open-source/litespeed-sapi/php https://www.litespeedtech.com/open-source/litespeed-sapi/php
- apocalyptic0n3 4y agoPHP-FPM can be so unreliable too. It'll just go down randomly without any warning or logs at all. As you said, it's impossible to debug what happens there and all you can really do is setup monitoring to detect it went down and automatically restart it.
- amq 4y agoPHP-FPM has been extremely reliable in my experience.
- jijji 4y agoPHP-FPM is very easy to debug. It's as simple as setting it up to use a listening socket in www.conf (located in i.e. /etc/php/8.1/fpm/pool.d) and then running a packet sniffer (i.e. ngrep) to listen on that socket, all messages back and forth are visible at that point.
- lapser 4y agoI don't know if I'd call usage of a packet sniffer "easy to debug". Seems like it's reasonable to expect some debug option that is easy to activate in dev environments that will give you the relevant information.
- jijji 4y agoThe back and forth communication is all that you care about with php-fpm, and rarely do you need to actually see it, unless you have php-fpm configured wrong for instance. The majority of debugging a php application means turning on debugging (i.e. ini_set 'display_errors' On and error_reporting('E_ALL')) and tailing a /var/log/nginx log file looking at what happened in your application.
- abrztam 4y agoWhat is the difference between this and Roadrunner? It seems to do the same stuff. https://github.com/roadrunner-server/roadrunner https://github.com/roadrunner-server/roadrunner
- floppydisc 4y agono. 1 feature: goofier branding
- kdunglas 4y agoThe approach isn't the same: Roadrunner executes php-cli and connects it to its web server through GRPC; FrankenPHP uses an ad-hoc SAPI, it is more like Apache's mod_php, the Go code uses the PHP interpreter as a library, it's all in the same process. RoadRunner only has a worker mode, and can only work with compatible apps; FrankenPHP has a "standard" mode compatible with all existing applications, and a worker mode that requires some code changes (like RR). RoadRunner runner uses PSR-7 HTTP messages; FrankenPHP uses plain old superglobals and streams (both in normal and in worker modes), they are reset after each handled request. RoadRunner is battle-tested and production ready; FrankenPHP is experimental and not yet ready for production use. FrankenPHP can also be used as a Go library to integrate PHP into any Go program or server (theoretically, it should be possible to integrate FrankenPHP into Traefik or the local Symfony web server, which are written in Go).
- bogdanu 4y agoSince it's not using PSR-7, does it mean that you could even run WordPress?
- kdunglas 4y agoI haven't tested it yet, but yes it's a stated goal.
- bdg 4y agoJust some experiences I've had putting large PHP frameworks into strange spaces: 1. Most PHP frameworks are designed to have all state destroyed at the end of a request. I was trying to integrate a commercial ecommerce framework with something like Road Runner and another one that I forget the name of. The framework had a DI system which provides each module with its own private instance of all injected instances, so having a "worker" that doesn't "boot" everything each request sounded like a good idea (boot was expensive, and a lot of logic was storing module-specific state in module-private instances). I hit a few barriers inside the framework, but actually a lot of them were due to dependencies on PHP global state following state-of-the-art conventions and best practices. It lead to spooky side-effects like cache from one page view loading into the next, and worse. Getting frameworks to run in a loop in PHP can often lead to sharing state in code that was designed in a way that state is assumed to be destroyed soon. 2. PHP depends on lots of unexpected things. If you're deep into language internals already you probably know this however. I was putting symfony2 into a PHP Unikernel a long time ago, and it drove me a bit crazy because everything in the file system, SAPI, locales, etc... it was all missing bridges to something it expected the OS to provide. I ended up making an immutable FS with Nginx and PHP all static linked to each other, but it was really just enough for a POC, a real production ready env would have been a lot more effort. The point is, PHP has a lot of unexpected "hooks" into environments it has grown up around that might be well hidden. Anyway, really cool project and I like the concept of using a SAPI, I think it has big potential.
- waynesonfire 4y ago
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- p4bl0 4y agoIf I understand it correctly the idea of worker mode is to have a persistent application running where you can have the same objects in memory from one request to another rather than relaunching the app from scratch (requiring files, constructing objects, fetching data from some database) again for each request. Is that it?
- deleted 4y ago[deleted]
- borancar 4y agoThis is amazing, and way more advanced than what was there. Going to definitely use it on the next project. Previously, there was https://github.com/deuill/go-php https://github.com/deuill/go-php which was PHP5 and PHP7, but you needed to build PHP with ZTS. I had to forke it to focus on PHP5 and bring some improvements - my primary goal was to port some legacy PHP over iteratively via the Strangler pattern. If it can still be useful to some, the fork is here - https://github.com/borancar/go-php https://github.com/borancar/go-php
- b_sanchez 4y agoI was in the conference (20221014, afup 2022), where frankenphp was released live. The conference was really interesting and answer many (if not all) of the questions raised in comments. I'v checked and unfortunately the video recording is not available for now, I will post a link here as son as available.