laitimes

Open source PHP application server: written in Go and supported for Early Hints

Have you ever dreamed of it

A modern PHP application server

Able to break through the shackles of tradition

Give your project unprecedented performance and flexibility?

so

FrankenPHP is exactly the solution you've been dreaming of!

Open source PHP application server: written in Go and supported for Early Hints

FrankenPHP is a modern PHP application server built on top of the Caddy web server, written in Go and C. It relies on Go's signature feature: goroutines.

Open source PHP application server: written in Go and supported for Early Hints

FrankenPHP features include:

  • Early Hints: This is a new feature of the web platform that allows websites to load 30% of the time in advance. FrankenPHP is the only PHP SAP that supports advance prompting
  • Worker mode: Start the application once and keep it in memory
  • Real-time capabilities: Built-in Mercure hub. Events are sent from the PHP application to all connected browsers, and they immediately receive the payload as JavaScript events
  • Scalable: Compatible with PHP 8.2+, most PHP extensions, and all Caddy modules
  • Easy to deploy: Cloud-native application delivery as a Docker image, compatible with Kubernetes and all modern cloud platforms. It is also possible to package your PHP application as a standalone, self-executing static binary.
  • 自动 HTTPS、HTTP/2 和 HTTP/3 支持等。

FrankenPHP Demo of Usage

One command runs all

A production-level PHP server can be up and running with a single command.

# Dockerdocker run -v $PWD:/app/public -p 443:443 \  dunglas/frankenphp
# 静态二进制文件./frankenphp php-server
# 命令行脚本./frankenphp php-cli /path/to/your/script.php           

The configuration is very simple

Only five lines of configuration required, powered by Caddy.

{
    # 启用 FrankenPHP
    frankenphp
    order php_server before file_server
}


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

FrankenPHP Highlights

Early Hints: FrankenPHP natively supports 103 Early Hints status codes, which can reduce the load time of web pages by up to 30%. It is supported in both normal mode and worker mode.

<?php
header('Link: </style.css>; rel=preload; as=style');headers_send(103);
// your slow algorithms and SQL queries 
echo <<<'HTML'
<!DOCTYPE html>
 <title>Hello FrankenPHP</title>
<link rel="stylesheet" href="style.css">HTML;           

Early Hints 是一种 HTTP 状态代码 (103 Early Hints),用于在最终响应之前发送初步 HTTP 响应。

This allows the server to send a hint to the browser about key sub-resources (e.g., stylesheets, key JavaScript) or sources that may be used by the web page while the server is busy generating the primary resource.

While waiting for a primary resource, the browser can use these prompts to warm up the connection and request sub-resources. That said, Early Hints helps browsers make the most of this "server think time" by doing some work ahead of time, which can make web pages load faster.

Worker mode: Start the application and reside it in memory, and FrankenPHP will process the incoming request in a matter of milliseconds.

Real-time functionality: FrankenPHP comes with a built-in Mercure Hub, Mercure allows events to be pushed in real-time to all connected devices, and they will receive JavaScript events instantly. No JS libraries or SDKs required.

Open source PHP application server: written in Go and supported for Early Hints

FrankenPHP works with any PHP application and makes the Laravel and Symfony projects faster than ever thanks to its official integration with the Worker pattern.

FrankenPHP can also be used as a standalone Go library to embed PHP in any application via net/http.

For more information, view:

https://github.com/dunglas/frankenphp

Read on