现代 PHP 应用服务器,用 Go 编写
FrankenPHP 是一个新的 PHP 应用服务器(基于 Caddy 构建),同时也是一个库,用于在 Go Web 服务器中嵌入 PHP 解释器.
curl https://frankenphp.dev/install.sh | sh开始使用!
只需使用一条命令即可启动并运行一个生产级别的 PHP 服务器!
# 在 Linux 或 macOS 上安装 FrankenPHP
curl https://frankenphp.dev/install.sh | sh
# 或者在 Windows 上,使用 PowerShell
irm https://frankenphp.dev/install.ps1 | iex
# 服务 public/ 目录
frankenphp php-server -r public/
# 运行命令行脚本
frankenphp php-cli script.php# 服务 public/ 目录
docker run -v $PWD:/app/public \
-p 443:443/tcp -p 443:443/udp \
dunglas/frankenphp
# 运行命令行脚
docker run -v $PWD:/app \
dunglas/frankenphp php script.phpAnatomy of a modern PHP server.
Every part was stitched on for a reason. Here's what keeps the creature alive.
The bolts
Automatic HTTPS
Certificates issued, renewed and revoked for you, with Let's Encrypt or ZeroSSL.
The brain
Worker mode
Boots your app once and keeps it in memory, ready in milliseconds.
The stitches
Caddy inside
The official PHP executor sewn into Caddy, with every Caddy module at hand.
One binary. No PHP-FPM.
Worker 模式
public/index.php
<?php
// Boot your app once
require __DIR__.'/vendor/autoload.php';
$app = new \App\Kernel();
$app->boot();
$handler = static function () use ($app) {
echo $app->handle($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
};
// …then serve request after request
while (\frankenphp_handle_request($handler)) {
gc_collect_cycles();
}Worker 脚本
启动您的应用一次,它便常驻内存!
直接明了
由 Symfony、API Platform、Laravel... 原生支持。
简单
仅需使用原始的超全局变量:无需 PSR-7。
快速
根据我们的基准测试,API Platform 应用上比 FPM 快 3.5 倍。
高效
FrankenPHP 用 Go 和 C 编写。它依赖 Go 的标志性功能:goroutines!
可选
即使您的应用不兼容 worker 模式,也可以按原样提供服务。
简易部署
以进程方式运行:一个二进制文件,无需外部服务。
观察者
代码更改后,工作程序会立即重新启动。
Caddyfile
localhost {
# 启用压缩(可选)
encode zstd br gzip
# 执行当前目录中的PHP文件并提供资产
php_server
}FrankenPHP 概览
可伸缩
与 PHP 8.2+、大多数 PHP 扩展和所有 Caddy 模块兼容。
唯一服务
设计简洁明了:只需要一个服务,只需要一个二进制文件!FrankenPHP 不需要 PHP-FPM,它使用为 Go web 服务器特别定制的自己的 SAPI。
易于部署
作为Docker 镜像的云原生应用交付。兼容 Kubernetes 和所有现代云平台。也可以将您的 PHP 应用程序打包为独立的、自执行的静态二进制文件。
工作模式
一次启动您的应用程序并保持其在内存中!它准备在几毫秒内处理传入请求。
103 早期提示
早期提示是 web 平台的一个全新特性,可以通过提前 30% 的时间加载网站。FrankenPHP 是唯一支持提前提示的 PHP SAPI!
实时功能
内置的Mercure 中心。从您的 PHP 应用程序发送事件到所有连接的浏览器,它们立即作为 JavaScript 事件接收负载!
Brotli、Zstandard 和 Gzip 压缩
现代压缩格式开箱即用。
结构化日志
为您的日志带来更加明确的格式和细节。
Prometheus 指标和追踪
内置的Prometheus 支持!
HTTP/2 & HTTP/3
对 HTTPS、HTTP/2 和 HTTP/3 的原生支持。
HTTPS 自动化
自动生成、续订和撤销 HTTPS 证书。
平滑重载
通过平滑重载零停机部署您的应用。
Born in a lab. Written in Go.
FrankenPHP is a Caddy module and a library: embed the PHP interpreter in any Go program and serve PHP scripts through net/http.
server, _ := frankenphp.NewServer("public/")
frankenphp.Init(frankenphp.WithServer(server))
defer frankenphp.Shutdown()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
server.ServeHTTP(w, r)
})比以往任何时候都更现代的 PHP!
- 使用嵌入在最先进的 Web 服务器中的官方 PHP 执行器:Caddy
- 原生支持 HTTP/1.1、HTTP/2 和 HTTP/3
- 自动生成和续订 HTTPS 证书(Let's Encrypt 或 ZeroSSL)
- 将您的 PHP 文件复制到文档根目录,就是这么简单!
- 为您的 PHP web 应用和命令行工具构建 独立的、自执行的、无依赖的二进制文件。
- 包括 OPcache 和 XDebug 在内的流行 PHP 扩展得到了原生支持!
Need a hand? We've got heart.
Les-Tilleuls.coop, the cooperative behind FrankenPHP, helps teams migrate, host and speed up their PHP apps.