418 points · by aquova · 2y ago · 196 comments
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.
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.
/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.
It has its pros and cons. In some cases it's actually quite nice to have a platform like Wildfly or the BEAM, or you knew so little about the future load peaks that you started with cheap shared hosting and hence PHP so when you outgrow it FastCGI and nginx is a much better option than a great rewrite to Golang.
Building in the languages and on the platforms you already know will always be much faster and more convenient than betting on someone else's 'bees knees'.
Huge misfortune of php is that because of the timing and huge popularity in relatively early days of web it got to be permanently associated with amateurs doing stupid shit. I was part of that early era, so trust me that php4 as bad as it was, was still fantastic compared to writing CGI scripts in C, or running mod_perl that you had to restart every time you edit some file.
Rails and Node and PHP have at least the decency to have the project's dependencies contained inside the project's own directory by default.
Build standalone, self-executable and dependencies-free binaries for your PHP web applications, and command-line tools.I’m in a pause in my career and I’m having a great time working on a "side" project in Django currently. Everything just works and makes sense, I just have to write business code and it gives me a nice app.
I’d be happy to try Go for fun and because deploying Python/Diango is a mess (at least without docker) but my project isn’t API first, it’s deliberately a traditional server side rendered app.
Every Go frameworks I stumbled upon looked like they were made to serve APIs and In the case of a 1 man team, it defeats the purpose of easy deployment since you will anyway need to code and deploy a full blown frontend (and front end fatigue is a big reason why my career is currently in pause).
On the API side (not what you wanted, but good looking) is sqlc + validator
Between all of those you have everything you want for a website.
Week 1 go is going to be a lot slower than Django or Rails. You're going to have a bit of bootstrapping to do for your project. By the end of the first month you will be a week or two behind but performance parity will be the same (you should have roughly the same feature cadence).
A good framework brings a lot to the table. With go you have to "solve" for that yourself. "How do I log a request" would be one of those first questions... the answer is "the standard logger is pretty good" and "Middleware is awesome". It's a question that has a simple, short, very common answer. One that works for web apps or CLI apps or ... It takes a bit but you end up embracing the idea that less is better
> because deploying Python/Diango is a mess (at least without docker)
I'm playing around with FastUI (disclosure - I'm not a programmer at all), so I'm in "day 0" position and would like to hear more on "day 1" side of things. Coming from Ansible side - it's easy peasy, just install things with pipenv and later `pipenv run ...`
Some of them try, but it's really hard to beat 20 years of development, real-life use cases, third party tools and docs, etc.
> deploying Python/Diango is a mess (at least without docker)
Install your django app in a venv, serve it with gunicorn behind apache/nginx... done. No docker required.
> Every Go frameworks I stumbled upon looked like they were made to serve APIs
Indeed, that's pretty much what Go was made for. And it's also the current trend.
> my project isn’t API first, it’s deliberately a traditional server side rendered app
Stick with Django then, because it remains an excellent choice for such apps. And these apps remain an excellent solution to a vast array of problems.
> front end fatigue is a big reason why my career is currently in pause
I'd argue you don't have to follow this trend to be useful. Actually, something like Django+Unpoly or HTMX probably covers 99% of the use cases with very low frontend development.
Fun and instantly understood.
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.
Is that because you have 18 years of experience, or would it be as easy for a new developer?
So I would say, knowing these two languages, PHP really is that easy to setup.
But it depends on what you’re trying to accomplish. If you’re sticking with defaults, it’s very easy - it’s less than ten minutes of work or seconds if you’re comfortable working with Docker.
On the other hand, let’s say that you’re running into problems scaling to handle more requests. You’ll end up having to tweak the max_workers setting. That takes a bit of experience or it can be a lot of ‘fun’ (in the Dwarf Fortress sense).
So yes and no. But a lot of people have been through this, have all the trauma you would receive and tend to be quite helpful.
You can do it!
It really is very easy.
It's a security nightmare. https://www.php.net/manual/en/security.apache.php
Even Apache httpd discourages the usage of mod_php. If installed, Apache recommends some extra configuration to limit memory leaks. https://cwiki.apache.org/confluence/display/HTTPD/php
What this does is give you a way to run your webserver + PHP as a single process, or single Docker container (instead of the traditional 2-container approach), and it also unlocks the ability to run PHP in a worker mode, where you have long-running PHP processes that have your framework loaded in memory ready to serve requests, instead of booting the framework on every request (so, much lower request latency).
Related reading:
https://blog.tjll.net/reverse-proxy-hot-dog-eating-contest-c...
Nginx Unit https://unit.nginx.org/ - like Apache + mod_php runs as a single service, handles the multiprocessing of php (and other languages), static files, reverse proxy and even lets you configure both itself and php via a single configuration (either as a file or dynamically at runtime, via a socket): https://unit.nginx.org/configuration/#php
Here is an IRL config example: https://github.com/PrivateBin/docker-unit-alpine/blob/master...
The resulting container image can be pretty small: https://hub.docker.com/r/privatebin/unit-alpine
I hardly every set up PHP (once each time I reinstall my desktop, which was last in ... 2018?) but I recall it being very quick and smooth using apt-get.
I don't recall doing anything else other than restarting apache.
Is it really that bad? The Apache configuration seems decent with something like PHP-FPM: https://news.ycombinator.com/item?id=40256843
LoadModule proxy_fcgi_module "/usr/lib/apache2/modules/mod_proxy_fcgi.so"
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
Here's a more full example of Nginx that's quite conceptually similar to how one would configure Apache, with installing the prerequisite packages: https://news.ycombinator.com/item?id=37443911There are also prebuilt container images that you can use to achieve similar results, this is just in case you want to do it yourself and have a look at what's under the hood a bit more.
In my eyes, that's certainly easier than configuring the Java app servers of old, like doing manual Tomcat or GlassFish configuration or whatever people spent time on back then. A single run command will usually be better regardless of the environment, but LAMP isn't all that bad either, when compared to the other stacks out there.
Also, having a binary makes it easy to bundle in an Electron app.
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.See the warning at the top of the page: https://www.php.net/manual/en/features.commandline.webserver...
Not sure it's even fair to consider it for comparison in this context.
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
The threads thing, the worker mode, etc., all of it is optional, but basic Caddy + PHP is already production-ready, I've been using this kind of setup for a while, and switching to FrankenPHP when you already have Caddy is completely harmless.
The only thing FrankenPHP does not is providing multiple versions of PHP in the same binary. For that, I'd still use Caddy + PHP-FPM, and it's fine.
Out of curiosity, is the performance the only blocker for putting this in prod ? If I were to have a small site, intended for a small number of users, what would I miss from other "prod-ready" environments ?
I'm pretty sure that this solves those specific issues (and more)
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...
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.
It's really awkward because Caddy by itself performs very well with PHP.
At the moment it is at the bottom as a "did not complete"
Show HN: FrankenPHP, an app server for PHP written in Go - https://news.ycombinator.com/item?id=33205282 - Oct 2022 (83 comments)
Caddy 2.8 - https://news.ycombinator.com/item?id=40517576
Has perf issues. Otherwise it's a really promising project.
Still want to repeat test and understand it better.
That being said, FrankenPHP makes it easy to enable HTTP cache with WordPress and simplifies the deployment story. There is a dedicated project for WordPress and FrankenPHP, that comes with a built-in HTTP cache tailored for WordPress (using the Souin Go library): https://github.com/StephenMiracle/frankenwp
This part is clear for me, but thank you for mentioning HTTP 103 too. I will not state for sure, but in my blurry memory, FPHP (FrankenPHP) was _slower_ than Apache+mod_php in that tests. But again, I won't say for sure, I just remember I was totally impressed as was expecting otherwise - much likely some subtle differences in setup on my side. If/when I have more precise info - I may ping you.
> That being said, FrankenPHP makes it easy to enable HTTP cache with WordPress and simplifies the deployment story. There is a dedicated project for WordPress and FrankenPHP, that comes with a built-in HTTP cache tailored for WordPress (using the Souin Go library): https://github.com/StephenMiracle/frankenwp
Thank you, have not seen that yet - may get idea or two from it. At glance, they just do naive `BYPASS_PATH_PREFIX` handling and that's all.
Beyond tests, I of course do prefer Nginx over Caddy and "simplifies the deployment story" doesn't resonate with my needs much yet - one of that things may change of course.
> 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.
[1] https://cwiki.apache.org/confluence/plugins/servlet/mobile?c...
docker 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: <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 certMy feeling is that FPM and its share nothing arquitecture has been both the key of PHPs success many years ago but also its condemnation.
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.
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.
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.
Some workloads won't see any benefits, others will. While your anecdata might be useful, it is just that, an anecdote.
I, for one, would love to be wrong about this and that FrankenPHP with all the other alternative runtimes actually brought benefits.
> The underlying engine that executes opcodes is the same.
Not exactly. FrankenPHP uses a ZTS build of PHP, which includes thread-support. Meaning you can actually spawn real-life threads in your PHP code with just a bit of work.
I've actually been working on a Parallel drop-in replacement that uses FrankenPHP/go instead of maintaining its own thread system.
Why would you run both?
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?
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.
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.
https://frankenphp.dev/docs/docker/#how-to-install-more-php-...
I'm sold.
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.'
- Roadrunner https://roadrunner.dev/ (also written in Go)
- Swoole https://www.swoole.com/ https://openswoole.com/
See https://laravel.com/docs/11.x/octane for Laravel specific framework integration.
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.
- ngx-php: https://github.com/rryqszq4/ngx-php
- Workerman: https://github.com/walkor/workerman
- ReactPHP: https://reactphp.org
And the most recent benchmarks:
https://www.techempower.com/benchmarks/#section=test&runid=0...
sigh
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/
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.