Skip to content

Commit cc8dfa8

Browse files
authored
docs: improve worker docs, and add internals docs (#2334)
1 parent a255768 commit cc8dfa8

33 files changed

Lines changed: 415 additions & 108 deletions

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Contributing
22

3+
For an overview of FrankenPHP's architecture (thread types, state machine, CGO boundary, request flow), see the [Internals documentation](docs/internals.md).
4+
35
## Compiling PHP
46

57
### With Docker (Linux)
@@ -299,7 +301,7 @@ The steps assume the following environment:
299301

300302
4. Debug Go files from CLion
301303

302-
- Right click on a *.go file in the Project view on the left
304+
- Right click on a \*.go file in the Project view on the left
303305
- Override file type → C/C++
304306

305307
Now you can place breakpoints in C, C++ and Go files.
@@ -348,7 +350,7 @@ Use GoLand for primary Go development, but the debugger cannot debug C code.
348350

349351
To debug C files from GoLand
350352

351-
- Right click on a *.c file in the Project view on the left
353+
- Right click on a \*.c file in the Project view on the left
352354
- Override file type → Go
353355

354356
Now you can place breakpoints in C, C++ and Go files.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Go to `https://localhost`, and enjoy!
177177
- [Demo app (Symfony) and benchmarks](https://github.com/dunglas/frankenphp-demo)
178178
- [Go library documentation](https://pkg.go.dev/github.com/dunglas/frankenphp)
179179
- [Contributing and debugging](https://frankenphp.dev/docs/contributing/)
180+
- [Internals (architecture overview)](docs/internals.md)
180181

181182
## Examples and Skeletons
182183

docs/cn/extension-workers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ while (frankenphp_handle_request($handler)) {
135135

136136
FrankenPHP 提供了钩子,用于在生命周期的特定点执行 Go 代码。
137137

138-
| 钩子类型 | 选项名称 | 签名 | 上下文与用例 |
139-
| :------- | :--------------------------- | :----------------------- | :--------------------------------------------------- |
140-
| **服务器** | `WithWorkerOnServerStartup` | `func()` | 全局设置。**只运行一次**。示例:连接到 NATS/Redis。 |
141-
| **服务器** | `WithWorkerOnServerShutdown` | `func()` | 全局清理。**只运行一次**。示例:关闭共享连接。 |
142-
| **线程** | `WithWorkerOnReady` | `func(threadID int)` | 每线程设置。在线程启动时调用。接收线程 ID。 |
143-
| **线程** | `WithWorkerOnShutdown` | `func(threadID int)` | 每线程清理。接收线程 ID。 |
138+
| 钩子类型 | 选项名称 | 签名 | 上下文与用例 |
139+
| :--------- | :--------------------------- | :------------------- | :-------------------------------------------------- |
140+
| **服务器** | `WithWorkerOnServerStartup` | `func()` | 全局设置。**只运行一次**。示例:连接到 NATS/Redis。 |
141+
| **服务器** | `WithWorkerOnServerShutdown` | `func()` | 全局清理。**只运行一次**。示例:关闭共享连接。 |
142+
| **线程** | `WithWorkerOnReady` | `func(threadID int)` | 每线程设置。在线程启动时调用。接收线程 ID。 |
143+
| **线程** | `WithWorkerOnShutdown` | `func(threadID int)` | 每线程清理。接收线程 ID。 |
144144

145145
### 示例
146146

docs/cn/hot-reload.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ FrankenPHP 包含一个内置的**热重载**功能,旨在极大改善开发
2525
>
2626
> 此功能仅适用于**开发环境**
2727
> 请勿在生产环境中启用 `hot_reload`,因为此功能不安全(会暴露敏感的内部细节)并且会降低应用程序的速度。
28-
>
28+
2929
```caddyfile
3030
localhost
3131
@@ -145,5 +145,5 @@ php_server {
145145
4. **接收**:浏览器通过 JavaScript 库监听,接收 Mercure 事件。
146146
5. **更新**
147147

148-
- 如果检测到 **Idiomorph**,它会获取更新的内容并修改当前的 HTML 以匹配新状态,即时应用更改而不会丢失状态。
149-
- 否则,将调用 `window.location.reload()` 来刷新页面。
148+
- 如果检测到 **Idiomorph**,它会获取更新的内容并修改当前的 HTML 以匹配新状态,即时应用更改而不会丢失状态。
149+
- 否则,将调用 `window.location.reload()` 来刷新页面。

docs/cn/worker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,4 @@ $handler = static function () use ($workerServer) {
184184
};
185185

186186
// ...
187+
```

docs/es/classic.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Sin ninguna configuración adicional, FrankenPHP opera en modo clásico. En este modo, FrankenPHP funciona como un servidor PHP tradicional, sirviendo directamente archivos PHP. Esto lo convierte en un reemplazo directo para PHP-FPM o Apache con mod_php.
44

55
Al igual que Caddy, FrankenPHP acepta un número ilimitado de conexiones y utiliza un [número fijo de hilos](config.md#caddyfile-config) para atenderlas. La cantidad de conexiones aceptadas y en cola está limitada únicamente por los recursos disponibles del sistema.
6-
El *pool* de hilos de PHP opera con un número fijo de hilos inicializados al inicio, comparable al modo estático de PHP-FPM. También es posible permitir que los hilos [escale automáticamente en tiempo de ejecución](performance.md#max_threads), similar al modo dinámico de PHP-FPM.
6+
El _pool_ de hilos de PHP opera con un número fijo de hilos inicializados al inicio, comparable al modo estático de PHP-FPM. También es posible permitir que los hilos [escalen automáticamente en tiempo de ejecución](performance.md#max_threads), similar al modo dinámico de PHP-FPM.
77

88
Las conexiones en cola esperarán indefinidamente hasta que un hilo de PHP esté disponible para atenderlas. Para evitar esto, puedes usar la configuración `max_wait_time` en la [configuración global de FrankenPHP](config.md#caddyfile-config) para limitar la duración que una petición puede esperar por un hilo de PHP libre antes de ser rechazada.
99
Adicionalmente, puedes establecer un [tiempo límite de escritura razonable en Caddy](https://caddyserver.com/docs/caddyfile/options#timeouts).
1010

11-
Cada instancia de Caddy iniciará solo un *pool* de hilos de FrankenPHP, el cual será compartido entre todos los bloques `php_server`.
11+
Cada instancia de Caddy iniciará solo un _pool_ de hilos de FrankenPHP, el cual será compartido entre todos los bloques `php_server`.

docs/es/compile.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ sudo make install
7979
Algunas características de FrankenPHP dependen de dependencias opcionales del sistema que deben instalarse.
8080
Alternativamente, estas características pueden deshabilitarse pasando etiquetas de compilación al compilador Go.
8181

82-
| Característica | Dependencia | Etiqueta de compilación para deshabilitarla |
83-
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------- | -------------------------------------------- |
84-
| Compresión Brotli | [Brotli](https://github.com/google/brotli) | nobrotli |
85-
| Reiniciar workers al cambiar archivos | [Watcher C](https://github.com/e-dant/watcher/tree/release/watcher-c) | nowatcher |
86-
| [Mercure](mercure.md) | [Biblioteca Mercure Go](https://pkg.go.dev/github.com/dunglas/mercure) (instalada automáticamente, licencia AGPL) | nomercure |
82+
| Característica | Dependencia | Etiqueta de compilación para deshabilitarla |
83+
| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
84+
| Compresión Brotli | [Brotli](https://github.com/google/brotli) | nobrotli |
85+
| Reiniciar workers al cambiar archivos | [Watcher C](https://github.com/e-dant/watcher/tree/release/watcher-c) | nowatcher |
86+
| [Mercure](mercure.md) | [Biblioteca Mercure Go](https://pkg.go.dev/github.com/dunglas/mercure) (instalada automáticamente, licencia AGPL) | nomercure |
8787

8888
## Compilar la aplicación Go
8989

docs/es/embed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ La forma más fácil de crear un binario para Linux es usar el constructor basad
6666
RUN EMBED=dist/app/ ./build-static.sh
6767
```
6868

69-
> [!CAUTION]
69+
> [!CAUTION]
7070
>
7171
> Algunos archivos `.dockerignore` (por ejemplo, el [`.dockerignore` predeterminado de Symfony Docker](https://github.com/dunglas/symfony-docker/blob/main/.dockerignore))
7272
> ignorarán el directorio `vendor/` y los archivos `.env`. Asegúrese de ajustar o eliminar el archivo `.dockerignore` antes de la construcción.

docs/es/extension-workers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ while (frankenphp_handle_request($handler)) {
135135

136136
FrankenPHP proporciona hooks para ejecutar código Go en puntos específicos del ciclo de vida.
137137

138-
| Tipo de Hook | Nombre de Opción | Firma | Contexto y Caso de Uso |
139-
| :----------- | :--------------------------- | :------------------- | :-------------------------------------------------------------------------- |
140-
| **Server** | `WithWorkerOnServerStartup` | `func()` | Configuración global. Se ejecuta **Una vez**. Ejemplo: Conectar a NATS/Redis. |
141-
| **Server** | `WithWorkerOnServerShutdown` | `func()` | Limpieza global. Se ejecuta **Una vez**. Ejemplo: Cerrar conexiones compartidas. |
142-
| **Thread** | `WithWorkerOnReady` | `func(threadID int)` | Configuración por hilo. Llamado cuando un hilo inicia. Recibe el ID del hilo. |
143-
| **Thread** | `WithWorkerOnShutdown` | `func(threadID int)` | Limpieza por hilo. Recibe el ID del hilo. |
138+
| Tipo de Hook | Nombre de Opción | Firma | Contexto y Caso de Uso |
139+
| :----------- | :--------------------------- | :------------------- | :------------------------------------------------------------------------------- |
140+
| **Servidor** | `WithWorkerOnServerStartup` | `func()` | Configuración global. Se ejecuta **Una vez**. Ejemplo: Conectar a NATS/Redis. |
141+
| **Servidor** | `WithWorkerOnServerShutdown` | `func()` | Limpieza global. Se ejecuta **Una vez**. Ejemplo: Cerrar conexiones compartidas. |
142+
| **Hilo** | `WithWorkerOnReady` | `func(threadID int)` | Configuración por hilo. Llamado cuando un hilo inicia. Recibe el ID del hilo. |
143+
| **Hilo** | `WithWorkerOnShutdown` | `func(threadID int)` | Limpieza por hilo. Recibe el ID del hilo. |
144144

145145
### Ejemplo
146146

docs/es/extensions.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ Mientras que el primer punto se explica por sí mismo, el segundo puede ser más
8787
Aunque algunos tipos de variables tienen la misma representación en memoria entre C/PHP y Go, algunos tipos requieren más lógica para ser usados directamente. Esta es quizá la parte más difícil cuando se trata de escribir extensiones porque requiere entender los internos del motor Zend y cómo se almacenan las variables internamente en PHP.
8888
Esta tabla resume lo que necesitas saber:
8989

90-
| Tipo PHP | Tipo Go | Conversión directa | Helper de C a Go | Helper de Go a C | Soporte para Métodos de Clase |
91-
|---------------------|--------------------------------|---------------------|---------------------------------------|----------------------------------------|-------------------------------|
92-
| `int` | `int64` | | - | - | |
93-
| `?int` | `*int64` | | - | - | |
94-
| `float` | `float64` | | - | - | |
95-
| `?float` | `*float64` | | - | - | |
96-
| `bool` | `bool` | | - | - | |
97-
| `?bool` | `*bool` | | - | - | |
98-
| `string`/`?string` | `*C.zend_string` | | `frankenphp.GoString()` | `frankenphp.PHPString()` | |
99-
| `array` | `frankenphp.AssociativeArray` | | `frankenphp.GoAssociativeArray()` | `frankenphp.PHPAssociativeArray()` | |
100-
| `array` | `map[string]any` | | `frankenphp.GoMap()` | `frankenphp.PHPMap()` | |
101-
| `array` | `[]any` | | `frankenphp.GoPackedArray()` | `frankenphp.PHPPackedArray()` | |
102-
| `mixed` | `any` | | `GoValue()` | `PHPValue()` | |
103-
| `callable` | `*C.zval` | | - | frankenphp.CallPHPCallable() | |
104-
| `object` | `struct` | | _Aún no implementado_ | _Aún no implementado_ | |
90+
| Tipo PHP | Tipo Go | Conversión directa | Helper de C a Go | Helper de Go a C | Soporte para Métodos de Clase |
91+
| ------------------ | ----------------------------- | ------------------ | --------------------------------- | ---------------------------------- | ----------------------------- |
92+
| `int` | `int64` || - | - ||
93+
| `?int` | `*int64` || - | - ||
94+
| `float` | `float64` || - | - ||
95+
| `?float` | `*float64` || - | - ||
96+
| `bool` | `bool` || - | - ||
97+
| `?bool` | `*bool` || - | - ||
98+
| `string`/`?string` | `*C.zend_string` || `frankenphp.GoString()` | `frankenphp.PHPString()` ||
99+
| `array` | `frankenphp.AssociativeArray` || `frankenphp.GoAssociativeArray()` | `frankenphp.PHPAssociativeArray()` ||
100+
| `array` | `map[string]any` || `frankenphp.GoMap()` | `frankenphp.PHPMap()` ||
101+
| `array` | `[]any` || `frankenphp.GoPackedArray()` | `frankenphp.PHPPackedArray()` ||
102+
| `mixed` | `any` || `GoValue()` | `PHPValue()` ||
103+
| `callable` | `*C.zval` || - | frankenphp.CallPHPCallable() ||
104+
| `object` | `struct` || _Aún no implementado_ | _Aún no implementado_ ||
105105

106106
> [!NOTE]
107107
>

0 commit comments

Comments
 (0)