Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ If your Docker version is lower than 23.0, the build will fail due to dockerigno

[Follow the instructions to compile from sources](https://frankenphp.dev/docs/compile/) and pass the `--debug` configuration flag.

## Running the Test Suite
## Running the test suite

```console
export CGO_CFLAGS=-O0 -g $(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)"
go test -race -v ./...
```

## Caddy Module
## Caddy module

Build Caddy with the FrankenPHP Caddy module:

Expand All @@ -65,7 +65,7 @@ The server is listening on `127.0.0.1:80`:
curl -vk http://127.0.0.1/phpinfo.php
```

## Minimal Test Server
## Minimal test server

Build the minimal test server:

Expand All @@ -88,7 +88,7 @@ The server is listening on `127.0.0.1:8080`:
curl -v http://127.0.0.1:8080/phpinfo.php
```

## Windows Development
## Windows development

1. Configure Git to always use `lf` line endings

Expand Down Expand Up @@ -155,7 +155,7 @@ curl -v http://127.0.0.1:8080/phpinfo.php
cd ../..
```

## Building Docker Images Locally
## Building Docker images locally

Print Bake plan:

Expand All @@ -181,7 +181,7 @@ Build FrankenPHP images from scratch for arm64 & amd64 and push to Docker Hub:
docker buildx bake -f docker-bake.hcl --pull --no-cache --push
```

## Debugging Segmentation Faults With Static Builds
## Debugging segmentation faults with static builds

1. Download the debug version of the FrankenPHP binary from GitHub or create your custom static build including debug symbols:

Expand All @@ -207,7 +207,7 @@ docker buildx bake -f docker-bake.hcl --pull --no-cache --push
7. Type `bt` in the GDB shell
8. Copy the output

## Debugging Segmentation Faults in GitHub Actions
## Debugging segmentation faults in GitHub Actions

1. Open `.github/workflows/tests.yml`
2. Enable PHP debug symbols
Expand Down Expand Up @@ -251,7 +251,7 @@ docker buildx bake -f docker-bake.hcl --pull --no-cache --push

9. When the bug is fixed, revert all these changes

## Development Environment Setup (WSL/Unix)
## Development environment setup (WSL/Unix)

### Initial setup

Expand All @@ -263,7 +263,7 @@ The steps assume the following environment:
- PHP built at: `/usr/local/bin/php`
- FrankenPHP source cloned to `~/frankenphp`

### CLion Setup for CGO glue/PHP Source Development
### CLion setup for CGO glue/PHP source development

1. Install CLion (on your host OS)

Expand Down Expand Up @@ -317,7 +317,7 @@ The steps assume the following environment:

---

### GoLand Setup for FrankenPHP Development
### GoLand setup for FrankenPHP development

Use GoLand for primary Go development, but the debugger cannot debug C code.

Expand All @@ -335,7 +335,7 @@ Use GoLand for primary Go development, but the debugger cannot debug C code.

---

### Go Configuration
### Go configuration

- Select Go Build
- Name `frankenphp`
Expand All @@ -357,7 +357,7 @@ Now you can place breakpoints in C, C++ and Go files.

---

### GoLand Setup on Windows
### GoLand setup on Windows

1. Follow the [Windows Development section](#windows-development)

Expand Down Expand Up @@ -385,13 +385,13 @@ Now you can place breakpoints in C, C++ and Go files.

---

### Debugging and Integration Notes
### Debugging and integration notes

- Use CLion for debugging PHP internals and `cgo` glue code
- Use GoLand for primary Go development and debugging
- FrankenPHP can be added as a run configuration in CLion for unified C/Go debugging if needed, but syntax highlighting won't work in Go files

## Misc Dev Resources
## Misc dev resources

- [PHP embedding in uWSGI](https://github.com/unbit/uwsgi/blob/master/plugins/php/php_plugin.c)
- [PHP embedding in NGINX Unit](https://github.com/nginx/unit/blob/master/src/nxt_php_sapi.c)
Expand All @@ -402,19 +402,19 @@ Now you can place breakpoints in C, C++ and Go files.
- [What the heck is TSRMLS_CC, anyway?](http://blog.golemon.com/2006/06/what-heck-is-tsrmlscc-anyway.html)
- [SDL bindings](https://pkg.go.dev/github.com/veandco/go-sdl2@v0.4.21/sdl#Main)

## Docker-Related Resources
## Docker-related resources

- [Bake file definition](https://docs.docker.com/build/customize/bake/file-definition/)
- [`docker buildx build`](https://docs.docker.com/engine/reference/commandline/buildx_build/)

## Useful Command
## Useful command

```console
apk add strace util-linux gdb
strace -e 'trace=!futex,epoll_ctl,epoll_pwait,tgkill,rt_sigreturn' -p 1
```

## Translating the Documentation
## Translating the documentation

To translate the documentation and the site into a new language,
follow these steps:
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FrankenPHP: Modern App Server for PHP
# FrankenPHP: modern app server for PHP

<h1 align="center"><a href="https://frankenphp.dev"><img src="frankenphp.png" alt="FrankenPHP" width="600"></a></h1>

Expand All @@ -14,9 +14,9 @@ FrankenPHP can also be used as a standalone Go library to embed PHP in any app u

<a href="https://dunglas.dev/2022/10/frankenphp-the-modern-php-app-server-written-in-go/"><img src="https://dunglas.dev/wp-content/uploads/2022/10/frankenphp.png" alt="Slides" width="600"></a>

## Getting Started
## Getting started

### Install Script
### Install script

On Linux and macOS, copy this line into your terminal to automatically
install an appropriate version for your platform:
Expand All @@ -31,7 +31,7 @@ On Windows, run this in PowerShell:
irm https://frankenphp.dev/install.ps1 | iex
```

### Standalone Binary
### Standalone binary

We provide FrankenPHP binaries for Linux, macOS and Windows
containing [PHP 8.5](https://www.php.net/releases/8.5/).
Expand All @@ -42,7 +42,7 @@ Windows archives contain the official PHP binary for Windows.

[Download FrankenPHP](https://github.com/php/frankenphp/releases)

### rpm Packages
### rpm packages
Comment thread
alexandre-daubois marked this conversation as resolved.

Our maintainers offer rpm packages for all systems using `dnf`. To install, run:

Expand All @@ -61,7 +61,7 @@ sudo dnf install pie-zts
sudo pie-zts install asgrim/example-pie-extension
```

### deb Packages
### deb packages

Our maintainers offer deb packages for all systems using `apt`. To install, run:

Expand All @@ -82,7 +82,7 @@ sudo apt install pie-zts
sudo pie-zts install asgrim/example-pie-extension
```

### apk Packages
### apk packages

Our maintainers offer apk packages for all systems using `apk`. To install, run:

Expand Down Expand Up @@ -160,9 +160,9 @@ Go to `https://localhost`, and enjoy!
- [Real-time](https://frankenphp.dev/docs/mercure/)
- [Logging](https://frankenphp.dev/docs/logging/)
- [Hot reloading](https://frankenphp.dev/docs/hot-reload/)
- [Efficiently Serving Large Static Files](https://frankenphp.dev/docs/x-sendfile/)
- [Efficiently serving large static files](https://frankenphp.dev/docs/x-sendfile/)
- [Configuration](https://frankenphp.dev/docs/config/)
- [Writing PHP Extensions in Go](https://frankenphp.dev/docs/extensions/)
- [Writing PHP extensions in Go](https://frankenphp.dev/docs/extensions/)
- [Docker images](https://frankenphp.dev/docs/docker/)
- [Deploy in production](https://frankenphp.dev/docs/production/)
- [Performance optimization](https://frankenphp.dev/docs/performance/)
Expand All @@ -179,7 +179,7 @@ Go to `https://localhost`, and enjoy!
- [Contributing and debugging](https://frankenphp.dev/docs/contributing/)
- [Internals (architecture overview)](docs/internals.md)

## Examples and Skeletons
## Examples and skeletons

- [Symfony](https://frankenphp.dev/docs/symfony/)
- [API Platform](https://api-platform.com/docs/symfony)
Expand Down
8 changes: 4 additions & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Security Policy
# Security policy

## Supported Versions
## Supported versions

Only the latest version is supported.
Please ensure that you're always using the latest release.

Binaries and Docker images are rebuilt nightly using the latest versions of dependencies.

## Security Model
## Security model

FrankenPHP embeds the PHP interpreter into a Go and Caddy server, so its trust boundaries span Go, C, and PHP.
Before auditing the project or reporting an issue, read the [security model documentation](docs/security.md),
which describes what is trusted, what is not, and which attack surfaces belong to FrankenPHP itself.

## Reporting a Vulnerability
## Reporting a vulnerability

If you believe you have discovered a security issue directly affecting FrankenPHP,
please do **NOT** report it publicly.
Expand Down
2 changes: 1 addition & 1 deletion docs/cn/embed.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ EMBED=/path/to/your/app ./build-static.sh
./my-app php-cli bin/console
```

## PHP Extensions
## PHP extensions

默认情况下,脚本将构建您项目的 `composer.json` 文件中所需的扩展(如果有的话)。
如果 `composer.json` 文件不存在,将构建默认扩展,如 [静态构建条目](static.md) 中所述。
Expand Down
6 changes: 3 additions & 3 deletions docs/cn/extension-workers.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 扩展 Worker
# 扩展 worker

扩展 Worker 使您的 [FrankenPHP 扩展](https://frankenphp.dev/docs/extensions/) 能够管理专用的 PHP 线程池,用于执行后台任务、处理异步事件或实现自定义协议。适用于队列系统、事件监听器、调度器等。

## 注册 Worker
## 注册 worker

### 静态注册

Expand Down Expand Up @@ -41,7 +41,7 @@ func init() {

如果您 [在没有 Caddy 的标准 Go 应用程序中嵌入 FrankenPHP](https://pkg.go.dev/github.com/dunglas/frankenphp#example-ServeHTTP),您可以在初始化选项时使用 `frankenphp.WithExtensionWorkers` 注册扩展 worker。

## 与 Worker 交互
## 与 worker 交互

一旦 worker 池激活,您就可以向其分派任务。这可以在 [导出到 PHP 的原生函数](https://frankenphp.dev/docs/extensions/#writing-the-extension) 中完成,也可以从任何 Go 逻辑中完成,例如 cron 调度器、事件监听器 (MQTT、Kafka) 或任何其他 goroutine。

Expand Down
2 changes: 1 addition & 1 deletion docs/cn/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
默认情况下,FrankenPHP 尝试在性能和易用性之间提供良好的折衷。
但是,通过使用适当的配置,可以大幅提高性能。

## 线程和 Worker 数量
## 线程和 worker 数量

默认情况下,FrankenPHP 启动的线程和 worker(在 worker 模式下)数量是可用 CPU 核心数的 2 倍。

Expand Down
2 changes: 1 addition & 1 deletion docs/cn/static.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ docker buildx bake \

参见:[自定义构建](#自定义构建)

### GitHub Token
### GitHub token

如果遇到了 GitHub API 速率限制,请在 `GITHUB_TOKEN` 的环境变量中设置 GitHub Personal Access Token:

Expand Down
8 changes: 4 additions & 4 deletions docs/cn/worker.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 使用 FrankenPHP Workers
# 使用 FrankenPHP workers

启动一次应用程序并将其保存在内存中。
FrankenPHP 将在几毫秒内处理传入请求。

## 启动 Worker 脚本
## 启动 worker 脚本

### Docker

Expand Down Expand Up @@ -129,14 +129,14 @@ docker run \
dunglas/frankenphp
```

### 在处理一定数量的请求后重启 Worker
### 在处理一定数量的请求后重启 worker

由于 PHP 最初不是为长时间运行的进程而设计的,仍有许多库和传统代码会泄漏内存。
在 worker 模式下使用此类代码的一个解决方法是在处理一定数量的请求后重启 worker 脚本:

前面的 worker 代码片段允许通过设置名为 `MAX_REQUESTS` 的环境变量来配置要处理的最大请求数。

### 手动重启 Workers
### 手动重启 workers

虽然可以在[文件更改时重启 workers](config.md#watching-for-file-changes),但也可以通过 [Caddy admin API](https://caddyserver.com/docs/api) 优雅地重启所有 workers。如果在你的 [Caddyfile](config.md#caddyfile-config) 中启用了 admin,你可以通过简单的 POST 请求 ping 重启端点,如下所示:

Expand Down
2 changes: 1 addition & 1 deletion docs/es/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Descubre más detalles sobre este servidor de aplicaciones en la grabación de e

<a href="https://dunglas.dev/2022/10/frankenphp-the-modern-php-app-server-written-in-go/"><img src="https://dunglas.dev/wp-content/uploads/2022/10/frankenphp.png" alt="Diapositivas" width="600"></a>

## Para Comenzar
## Para comenzar

En Windows, usa [WSL](https://learn.microsoft.com/es-es/windows/wsl/) para ejecutar FrankenPHP.

Expand Down
2 changes: 1 addition & 1 deletion docs/es/extension-workers.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Extension Workers
# Extension workers

Los Extension Workers permiten que tu [extensión FrankenPHP](https://frankenphp.dev/docs/extensions/) gestione un pool dedicado de hilos PHP para ejecutar tareas en segundo plano, manejar eventos asíncronos o implementar protocolos personalizados. Útil para sistemas de colas, listeners de eventos, programadores, etc.

Expand Down
2 changes: 1 addition & 1 deletion docs/extension-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ while (frankenphp_handle_request($handler)) {

FrankenPHP provides hooks to execute Go code at specific points in the lifecycle.

| Hook Type | Option Name | Signature | Context & Use Case |
| Hook type | Option name | Signature | Context & use case |
| :--------- | :--------------------------- | :------------------- | :--------------------------------------------------------------------- |
| **Server** | `WithWorkerOnServerStartup` | `func()` | Global setup. Run **Once**. Example: Connect to NATS/Redis. |
| **Server** | `WithWorkerOnServerShutdown` | `func()` | Global cleanup. Run **Once**. Example: Close shared connections. |
Expand Down
10 changes: 5 additions & 5 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Once you've integrated your extension into FrankenPHP as demonstrated in the pre
While some variable types have the same memory representation between C/PHP and Go, some types require more logic to be directly used. This is probably the hardest part when it comes to writing extensions because it requires understanding the internals of the Zend Engine and how variables are stored internally in PHP.
This table summarizes what you need to know:

| PHP type | Go type | Direct conversion | C to Go helper | Go to C helper | Class Methods Support |
| PHP type | Go type | Direct conversion | C to Go helper | Go to C helper | Class methods support |
| ------------------ | ----------------------------- | ----------------- | --------------------------------- | ---------------------------------- | --------------------- |
| `int` | `int64` | ✅ | - | - | ✅ |
| `?int` | `*int64` | ✅ | - | - | ✅ |
Expand All @@ -175,7 +175,7 @@ This table summarizes what you need to know:

If you refer to the code snippet of the previous section, you can see that helpers are used to convert the first parameter and the return value. The second and third parameters of our `repeat_this()` function don't need to be converted, as the memory representation of the underlying types is the same for both C and Go.

#### Working with Arrays
#### Working with arrays

FrankenPHP provides native support for PHP arrays through `frankenphp.AssociativeArray` or direct conversion to a map or slice.

Expand Down Expand Up @@ -269,7 +269,7 @@ func process_data_packed(arr *C.zend_array) unsafe.Pointer {
- **Nested Arrays** - Arrays can be nested and will convert all supported types automatically (`int64`, `float64`, `string`, `bool`, `nil`, `AssociativeArray`, `map[string]any`, `[]any`)
- **Objects are not supported** - Currently, only scalar types and arrays can be used as values. Providing an object will result in a `null` value in the PHP array.

##### Available methods: Packed and Associative
##### Available methods: packed and associative

- `frankenphp.PHPAssociativeArray(arr frankenphp.AssociativeArray) unsafe.Pointer` - Convert to an ordered PHP array with key-value pairs
- `frankenphp.PHPMap(arr map[string]any) unsafe.Pointer` - Convert a map to an unordered PHP array with key-value pairs
Expand Down Expand Up @@ -599,7 +599,7 @@ func (sp *StringProcessorStruct) Process(input *C.zend_string, mode int64) unsaf

The generator supports organizing your PHP extension's functions, classes, and constants under a namespace using the `//export_php:namespace` directive. This helps avoid naming conflicts and provides better organization for your extension's API.

#### Declaring a Namespace
#### Declaring a namespace

Use the `//export_php:namespace` directive at the top of your Go file to place all exported symbols under a specific namespace:

Expand Down Expand Up @@ -696,7 +696,7 @@ The `frankenphp.RegisterExtension()` function simplifies the extension registrat

In this example, our new function will trigger a goroutine that logs a message in Caddy's logs.

#### Define the PHP Function
#### Define the PHP function

To allow PHP to call our function, we need to define a corresponding PHP function. For this, we will create a stub file, for example, `extension.stub.php`, which will contain the following code:

Expand Down
Loading
Loading