Skip to content

Commit d5558ab

Browse files
committed
add documentation for worker config inside php or php_server blocks
1 parent 3af8a30 commit d5558ab

9 files changed

Lines changed: 551 additions & 89 deletions

File tree

docs/cn/config.md

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,37 @@ localhost {
8686
# ...
8787
```
8888

89-
如果在同一服务器上运行多个应用,还可以定义多个 worker:
89+
Worker 块也可以在 `php``php_server` 块内定义。在这种情况下,worker 继承父指令的环境变量和根路径,并且只能由该特定域访问:
90+
91+
```caddyfile
92+
{
93+
frankenphp
94+
}
95+
example.com {
96+
root /path/to/app
97+
php_server {
98+
root <path>
99+
worker {
100+
file <path, 可以相对于 root>
101+
num <num>
102+
env <key> <value>
103+
watch <path>
104+
name <name>
105+
}
106+
}
107+
}
108+
```
90109

110+
如果在同一服务器上运行多个应用,还可以定义多个 worker:
91111
```caddyfile
92112
{
93113
frankenphp {
94114
worker /path/to/app/public/index.php <num>
95-
worker /path/to/other/public/index.php <num>
115+
worker {
116+
file /path/to/other/public/index.php
117+
num <num>
118+
env APP_ENV dev
119+
}
96120
}
97121
}
98122
@@ -103,7 +127,34 @@ app.example.com {
103127
104128
other.example.com {
105129
root /path/to/other/public
106-
php_server
130+
php_server {
131+
env APP_ENV dev
132+
}
133+
}
134+
135+
# ...
136+
```
137+
138+
等效于
139+
140+
```caddyfile
141+
{
142+
frankenphp
143+
}
144+
145+
app.example.com {
146+
php_server {
147+
root /path/to/app/public
148+
worker index.php <num>
149+
}
150+
}
151+
152+
other.example.com {
153+
php_server {
154+
root /path/to/other/public
155+
env APP_ENV dev
156+
worker index.php <num>
157+
}
107158
}
108159
# ...
109160
```
@@ -138,7 +189,7 @@ route {
138189

139190
```caddyfile
140191
php_server [<matcher>] {
141-
root <directory> # 设置站点的根目录。默认值:`root` 指令。如果未指定,默认将使用 current_working_dir/public 目录。
192+
root <directory> # 设置站点的根目录。默认值:`root` 指令。如果未指定
142193
split_path <delim...> # 设置用于将 URI 拆分为两部分的子字符串。第一个匹配的子字符串将用于从路径中拆分“路径信息”。第一个部分以匹配的子字符串为后缀,并将假定为实际资源(CGI 脚本)名称。第二部分将设置为PATH_INFO,供脚本使用。默认值:`.php`
143194
resolve_root_symlink false # 禁用将 `root` 目录在符号链接时将其解析为实际值(默认启用)。
144195
env <key> <value> # 设置额外的环境变量,可以设置多个环境变量。
@@ -155,6 +206,23 @@ php_server [<matcher>] {
155206

156207
## PHP 配置
157208

209+
您还可以使用 `frankenphp` 块中的 `php_ini` 指令更改 PHP 配置:
210+
211+
```caddyfile
212+
{
213+
frankenphp {
214+
php_ini memory_limit 256M
215+
216+
# 或者
217+
218+
php_ini {
219+
memory_limit 256M
220+
max_execution_time 15
221+
}
222+
}
223+
}
224+
```
225+
158226
要加载 [其他 PHP INI 配置文件](https://www.php.net/manual/en/configuration.file.php#configuration.file.scan)
159227
可以使用 `PHP_INI_SCAN_DIR` 环境变量。
160228
设置后,PHP 将加载给定目录中存在 `.ini` 扩展名的所有文件。

docs/cn/worker.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,45 @@
33
启动应用程序一次并将其保存在内存中。
44
FrankenPHP 将在几毫秒内处理传入的请求。
55

6+
## Caddyfile 配置
7+
8+
Worker 块可以通过两种方式定义:
9+
10+
1. 在全局 frankenphp 块中,如[配置文档](config.md#caddyfile-config)中所述:
11+
12+
```caddyfile
13+
{
14+
frankenphp {
15+
worker {
16+
file <路径>
17+
num <数量>
18+
env <键> <值>
19+
watch <路径>
20+
name <名称>
21+
}
22+
}
23+
}
24+
```
25+
26+
2. 在 php 或 php_server 块内:
27+
28+
```caddyfile
29+
example.com {
30+
root /path/to/app
31+
php_server {
32+
worker {
33+
file <路径>
34+
num <数量>
35+
env <键> <值>
36+
watch <路径>
37+
name <名称>
38+
}
39+
}
40+
}
41+
```
42+
43+
当在 php 或 php_server 块内定义时,worker 会继承父指令的环境变量和根路径,并且只能由该特定的 php 或 php_server 访问。
44+
645
## 启动 Worker 脚本
746

847
### Docker

docs/config.md

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,38 @@ Alternatively, you may use the one-line short form of the `worker` option:
9494
# ...
9595
```
9696

97+
Worker blocks can also be defined inside a `php` or `php_server` block. In this case, the worker inherits environment variables and root path from the parent directive and is only accessible by that specific domain:
98+
99+
```caddyfile
100+
{
101+
frankenphp
102+
}
103+
example.com {
104+
root /path/to/app
105+
php_server {
106+
root <path>
107+
worker {
108+
file <path, can be relative to root>
109+
num <num>
110+
env <key> <value>
111+
watch <path>
112+
name <name>
113+
}
114+
}
115+
}
116+
```
117+
97118
You can also define multiple workers if you serve multiple apps on the same server:
98119

99120
```caddyfile
100121
{
101122
frankenphp {
102123
worker /path/to/app/public/index.php <num>
103-
worker /path/to/other/public/index.php <num>
124+
worker {
125+
file /path/to/other/public/index.php
126+
num <num>
127+
env APP_ENV dev
128+
}
104129
}
105130
}
106131
@@ -111,7 +136,34 @@ app.example.com {
111136
112137
other.example.com {
113138
root /path/to/other/public
114-
php_server
139+
php_server {
140+
env APP_ENV dev
141+
}
142+
}
143+
144+
# ...
145+
```
146+
147+
Is equivalent to
148+
149+
```caddyfile
150+
{
151+
frankenphp
152+
}
153+
154+
app.example.com {
155+
php_server {
156+
root /path/to/app/public
157+
worker index.php <num>
158+
}
159+
}
160+
161+
other.example.com {
162+
php_server {
163+
root /path/to/other/public
164+
env APP_ENV dev
165+
worker index.php <num>
166+
}
115167
}
116168
117169
# ...
@@ -149,7 +201,7 @@ The `php_server` and the `php` directives have the following options:
149201

150202
```caddyfile
151203
php_server [<matcher>] {
152-
root <directory> # Sets the root folder to the site. Default: `root` directive. If not specified, it will use the current_working_dir/public directory by default.
204+
root <directory> # Sets the root folder to the site. Default: `root` directive.
153205
split_path <delim...> # Sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the script to use. Default: `.php`
154206
resolve_root_symlink false # Disables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists (enabled by default).
155207
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
@@ -212,7 +264,7 @@ This is an opt-in configuration that needs to be added to the global options in
212264
```caddyfile
213265
{
214266
servers {
215-
enable_full_duplex
267+
enable_full_duplex
216268
}
217269
}
218270
```
@@ -252,16 +304,16 @@ You can also change the PHP configuration using the `php_ini` directive in the `
252304

253305
```caddyfile
254306
{
255-
frankenphp {
256-
php_ini memory_limit 256M
307+
frankenphp {
308+
php_ini memory_limit 256M
257309
258-
# or
310+
# or
259311
260-
php_ini {
261-
memory_limit 256M
262-
max_execution_time 15
263-
}
264-
}
312+
php_ini {
313+
memory_limit 256M
314+
max_execution_time 15
315+
}
316+
}
265317
}
266318
```
267319

0 commit comments

Comments
 (0)