跳到内容
FrankenPHP
Esc
↑↓导航↵打开⌘J预览

现代 PHP 应用服务器,用 Go 编写

FrankenPHP 是一个新的 PHP 应用服务器(基于 Caddy 构建),同时也是一个库,用于在 Go Web 服务器中嵌入 PHP 解释器.

curl https://frankenphp.dev/install.sh | sh
开始使用
  • 原生支持
  • Drupal
  • Sulu
  • WordPress
  • Laravel
  • Symfony
  • API Platform
  • Magento

开始使用!

只需使用一条命令即可启动并运行一个生产级别的 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

Worker 模式

The FrankenPHP mascot in a hard hat, driving an excavator

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 模式,也可以按原样提供服务。

  • 简易部署

    以进程方式运行:一个二进制文件,无需外部服务。

  • 观察者

    代码更改后,工作程序会立即重新启动。

Read the worker docs →

Caddyfile

localhost {
    # 启用压缩(可选)
    encode zstd br gzip
    # 执行当前目录中的PHP文件并提供资产
    php_server
}

配置如此简单!

只需三行配置:现在,您所需要的就是启动一个生产级别的 PHP 服务器(自动 HTTPS、HTTP/3、Brotli 压缩...),由 Caddy 提供支持。

  • HTTPS ✓
  • HTTP/3 ✓
  • zstd · br · gzip ✓
  • Early Hints ✓
文档 →

FrankenPHP 概览

The FrankenPHP elephant and the Go gopher in a laboratory, lightning crackling between them
Go + C + PHP

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)
})
Use FrankenPHP as a Go library →

比以往任何时候都更现代的 PHP!

  • 使用嵌入在最先进的 Web 服务器中的官方 PHP 执行器:Caddy
  • 原生支持 HTTP/1.1、HTTP/2 和 HTTP/3
  • 自动生成和续订 HTTPS 证书(Let's Encrypt 或 ZeroSSL)
  • 将您的 PHP 文件复制到文档根目录,就是这么简单!
  • 为您的 PHP web 应用和命令行工具构建 独立的、自执行的、无依赖的二进制文件。
  • 包括 OPcache 和 XDebug 在内的流行 PHP 扩展得到了原生支持!
尝试一下
The FrankenPHP mascot hugging a big red heart

Need a hand? We've got heart.

Les-Tilleuls.coop, the cooperative behind FrankenPHP, helps teams migrate, host and speed up their PHP apps.