Pure PHP web+socket server, serves 10x more concurrent PHP than NginX+FPM
Qbix Server
Yesterday, I posted on Reddit about a web server I launched that's written in pure userland PHP, managed its own preforked workers, and removed the need for NGINX and PHP-FPM.
It was already able to run 10x more concurrent workers (e.g. 1600 workers on an 8GB server).
The biggest bottleneck in PHP hosting is *memory*. Each php-fpm worker loads your entire framework independently: 30–60MB per worker. On an 8GB server, that's ~160 workers max. That's your ceiling for concurrent PHP requests.
Well, Qbix Server forks workers *after* preloading your classes. Thanks to copy-on-write from the operating system, all that shared code (framework, config, autoloader) uses memory only once. Each worker adds maybe 3-6MB for its per-request data.
This means you get to run 10x more workers, and each worker actually loads much *faster* because you don't have to bootstrap your entire framework, config, etc. on every request.
https://github.com/Qbix/webserver
But wait... it got faster.
Yesterday, some people were complaining that a userland-PHP server was "only" 70% as fast as NGINX for serving static files. Well, it's 24 hours later, and I'm back, baby! After caching more, it turns out that it's now 25-35% FASTER than NGINX even for static files (as long as you keepalive connections).
Don't believe me? Run the benchmarks. It comes with a test suite now.
But wait... it now supports sockets
Yes, it is wire-compatible with socket.io, and bundles it out of the box (no need for npm). Now you can just drop PHP files into folders, in order to:
Handle HTTP Requests. (Cleanup after request is handled.)
Handle Web Sockets. (Long-lived, cleanup after disconnect.)
Handle Rooms. (Long-lived, cleanup after last websocket leaves.)
In my opinion, the coolest thing is that this retains all the things that made PHP great:
Shared-nothing. No way to have memory or secrets leak between requests.
Normie-friendly. Just drop files into folders and things just work! No need for hot-reload even. Not even for websockets and rooms -- the old handler will work for the old connections, while the new one is loaded for the new ones.
Sequential processing, sure it means you occasionally miss out on fanning out concurrent I/O races, but it's much easier to understand the code.
Give it a try! It's MIT licensed. Enjoy 😄
Who this is for:
- PHP Developers who want to host things
- Normies who don't want to install and configure apache/nginx/varnish/go/ssl certificates/mysql/etc.
- People who just get the standalone binary and can host on their computer, without the internet even.
This was taken from the much larger all-in-one PHP platform: