我构建了世界上最快的 PHP 网络服务器
I built the fastest PHP webserver in the world

原始链接: https://qbixserver.com

大多数 PHP 环境依赖阻塞式 I/O,由于运行多个工作进程(worker)会带来高昂的内存开销,这在传统上限制了其扩展性。虽然 Swoole、FrankenPHP 和 RoadRunner 等解决方案试图解决这一问题,但在处理现有代码库时仍面临局限。 Qbix 引入了一种利用 `pcntl_fork()` 系统调用的高效替代方案。通过在派生进程(fork)之前将应用程序框架加载到父进程中,服务器利用了 Linux 内核的“写时复制”(COW)内存管理机制。这使得数千个工作进程能够共享同一内存空间,仅在处理特定请求时对修改的数据消耗额外的内存。 这种方法改变了 PHP 扩展的经济性:开发者不再受限于少量资源密集型工作进程(如 PHP-FPM),而是能以极低的成本启动数千个工作进程。由于该系统能在此规模下有效处理阻塞式 I/O,因此无需特殊的扩展或复杂的异步编程。Qbix 通过标准的纯 PHP 代码,有效地实现了高性能并发。

一篇题为《我构建了世界上最快的 PHP Web 服务器》的文章在 Hacker News 上引发了激烈的讨论。持怀疑态度的评论者质疑该项目的营销方式,指出作者将“没有使用 Nginx、Redis 或 Docker”等情况包装成功能特性,而这些实际上可能是架构上的疏漏。 批评者认为,该项目的文案看起来像是人工智能生成的,缺乏对软件工程权衡的真正理解,并将一些细枝末节吹捧为重大突破。这引发了关于大语言模型(LLM)的更广泛讨论,用户指出 AI 往往难以区分必要特性与基本功能,无法捕捉到对人类开发者而言真正相关的内容。 尽管一些支持者指出,在没有 Nginx 等外部依赖的情况下运行生产级 PHP 服务器是一项有效的技术成就,但主流观点认为,该项目的表达缺乏必要的逻辑支撑,难以被严肃对待。总的来说,这篇帖子的讨论既是对“AI 生成”式营销文案的批评,也凸显了专业语境在技术文档中的重要性。
相关文章

原文

The vast majority of PHP code — WordPress plugins, Laravel packages, every PDO::query() and file_get_contents() ever written — uses blocking I/O. Swoole’s coroutines can’t help with code that doesn’t yield. FrankenPHP and RoadRunner use the same worker-count-limited model as fpm.

Qbix takes a different approach: run many workers. The server loads your entire framework into a parent process, then calls pcntl_fork() to create workers. The kernel marks the parent’s pages copy-on-write. Workers share every loaded class — they only pay for pages they actually write to during the request.

A WordPress-like request dirties 30 pages = 120KB on Linux. So 200MB doesn’t buy 4 workers (like fpm) — it buys thousands. Each one blocks on its database query, and that’s fine. Blocking I/O doesn’t matter when you have enough workers. COW is what makes “enough workers” cost 47MB instead of 16GB.

This is pure userland PHP. No kernel module, no C extension, no custom allocator. Just pcntl_fork() after loading everything, and the OS does the rest.

We proposed this for PHP core as switch_global_context(). While that works its way through the RFC process, the server does it in userland today.

联系我们 contact @ memedata.com