Skip to content
1 change: 0 additions & 1 deletion caddy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (f *FrankenPHPApp) Start() error {
workerOpts := []frankenphp.WorkerOption{
frankenphp.WithWorkerEnv(w.Env),
frankenphp.WithWorkerWatchMode(w.Watch),
frankenphp.WithWorkerMaxFailures(w.MaxConsecutiveFailures),
}

opts = append(opts, frankenphp.WithWorkers(w.Name, repl.ReplaceKnown(w.FileName, ""), w.Num, workerOpts...))
Expand Down
19 changes: 3 additions & 16 deletions caddy/workerconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type workerConfig struct {
Watch []string `json:"watch,omitempty"`
// The path to match against the worker
MatchPath []string `json:"match_path,omitempty"`
// MaxConsecutiveFailures sets the maximum number of consecutive failures before panicking (defaults to 6, set to -1 to never panick)
MaxConsecutiveFailures int `json:"max_consecutive_failures,omitempty"`
}

func parseWorkerConfig(d *caddyfile.Dispenser) (workerConfig, error) {
Expand Down Expand Up @@ -109,21 +107,10 @@ func parseWorkerConfig(d *caddyfile.Dispenser) (workerConfig, error) {
caddyMatchPath.Provision(caddy.Context{})
wc.MatchPath = ([]string)(caddyMatchPath)
case "max_consecutive_failures":
if !d.NextArg() {
return wc, d.ArgErr()
}

v, err := strconv.Atoi(d.Val())
if err != nil {
return wc, err
}
if v < -1 {
return wc, errors.New("max_consecutive_failures must be >= -1")
}

wc.MaxConsecutiveFailures = int(v)
_ = d.NextArg()
caddy.Log().Warn("frankenphp: worker max_consecutive_failures is deprecated")
default:
allowedDirectives := "name, file, num, env, watch, match, max_consecutive_failures"
allowedDirectives := "name, file, num, env, watch, match"
return wc, wrongSubDirectiveError("worker", allowedDirectives, v)
}
}
Expand Down
1 change: 0 additions & 1 deletion docs/cn/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ localhost {
env <key> <value> # 设置一个额外的环境变量为给定的值。可以多次指定以设置多个环境变量。
watch <path> # 设置要监视文件更改的路径。可以为多个路径多次指定。
name <name> # 设置worker的名称,用于日志和指标。默认值:worker文件的绝对路径。
max_consecutive_failures <num> # 设置在工人被视为不健康之前的最大连续失败次数,-1意味着工人将始终重新启动。默认值:6。
}
}
}
Expand Down
19 changes: 0 additions & 19 deletions docs/cn/worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,6 @@ docker run \
curl -X POST http://localhost:2019/frankenphp/workers/restart
```

### Worker 故障

如果 worker 脚本因非零退出代码而崩溃,FrankenPHP 将使用指数退避策略重启它。
如果 worker 脚本保持运行的时间超过上次退避 × 2,
它将不会惩罚 worker 脚本并再次重启它。
但是,如果 worker 脚本在短时间内继续以非零退出代码失败
(例如,脚本中有拼写错误),FrankenPHP 将崩溃并出现错误:`too many consecutive failures`。

可以在你的 [Caddyfile](config.md#caddyfile-配置) 中使用 `max_consecutive_failures` 选项配置连续失败的次数:

```caddyfile
frankenphp {
worker {
# ...
max_consecutive_failures 10
}
}
```

## 超全局变量行为

[PHP 超全局变量](https://www.php.net/manual/zh/language.variables.superglobals.php)(`$_SERVER`、`$_ENV`、`$_GET`...)
Expand Down
1 change: 0 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ You can also explicitly configure FrankenPHP using the [global option](https://c
env <key> <value> # Sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
watch <path> # Sets the path to watch for file changes. Can be specified more than once for multiple paths.
name <name> # Sets the name of the worker, used in logs and metrics. Default: absolute path of worker file
max_consecutive_failures <num> # Sets the maximum number of consecutive failures before the worker is considered unhealthy, -1 means the worker will always restart. Default: 6.
}
}
}
Expand Down
1 change: 0 additions & 1 deletion docs/fr/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ L'[option globale](https://caddyserver.com/docs/caddyfile/concepts#global-option
env <key> <value> # Définit une variable d'environnement supplémentaire avec la valeur donnée. Peut être spécifié plusieurs fois pour régler plusieurs variables d'environnement.
watch <path> # Définit le chemin d'accès à surveiller pour les modifications de fichiers. Peut être spécifié plusieurs fois pour plusieurs chemins.
name <name> # Définit le nom du worker, utilisé dans les journaux et les métriques. Défaut : chemin absolu du fichier du worker
max_consecutive_failures <num> # Définit le nombre maximum d'échecs consécutifs avant que le worker ne soit considéré comme défaillant, -1 signifie que le worker redémarre toujours. Par défaut : 6.
}
}
}
Expand Down
18 changes: 0 additions & 18 deletions docs/fr/worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,6 @@ curl -X POST http://localhost:2019/frankenphp/workers/restart
>
> C'est une fonctionnalité expérimentale et peut être modifiée ou supprimée dans le futur.

### Worker Failures

Si un script de worker se plante avec un code de sortie non nul, FrankenPHP le redémarre avec une stratégie de backoff exponentielle.
Si le script worker reste en place plus longtemps que le dernier backoff \* 2, FrankenPHP ne pénalisera pas le script et le redémarrera à nouveau.
Toutefois, si le script de worker continue d'échouer avec un code de sortie non nul dans un court laps de temps
(par exemple, une faute de frappe dans un script), FrankenPHP plantera avec l'erreur : `too many consecutive failures` (trop d'échecs consécutifs).

Le nombre d'échecs consécutifs peut être configuré dans votre [Caddyfile](config.md#configuration-du-caddyfile) avec l'option `max_consecutive_failures` :

```caddyfile
frankenphp {
worker {
# ...
max_consecutive_failures 10
}
}
```

## Comportement des superglobales

[Les superglobales PHP](https://www.php.net/manual/fr/language.variables.superglobals.php) (`$_SERVER`, `$_ENV`, `$_GET`...)
Expand Down
1 change: 0 additions & 1 deletion docs/ja/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ localhost {
env <key> <value> # 追加の環境変数を指定された値に設定する。複数の環境変数に対して複数回指定することができます。
watch <path> # ファイル変更を監視するパスを設定します。複数のパスに対して複数回指定できます。
name <name> # ワーカーの名前を設定します。ログとメトリクスで使用されます。デフォルト: ワーカーファイルの絶対パス
max_consecutive_failures <num> # workerが不健全とみなされるまでの、連続失敗の最大回数を設定します。 -1 はワーカーを常に再起動することを意味します。デフォルトは 6 です。
}
}
}
Expand Down
19 changes: 0 additions & 19 deletions docs/ja/worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,6 @@ PHPはもともと長時間実行されるプロセス向けに設計されて
curl -X POST http://localhost:2019/frankenphp/workers/restart
```

### ワーカーの失敗

ワーカースクリプトがゼロ以外の終了コードでクラッシュした場合、FrankenPHP は指数的バックオフ戦略を用いて再起動を行います。
ワーカースクリプトが最後のバックオフ時間 × 2 より長く稼働し続けた場合、
それ以降の再起動ではペナルティを科しません。
しかし、スクリプトにタイプミスがあるなど短時間で何度もゼロ以外の終了コードで失敗し続ける場合、
FrankenPHP は`too many consecutive failures`というエラーとともにクラッシュします。

連続失敗の回数上限は、[Caddyfile](config.md#caddyfile-config)の`max_consecutive_failures`オプションで設定できます:

```caddyfile
frankenphp {
worker {
# ...
max_consecutive_failures 10
}
}
```

## スーパーグローバルの動作

[PHPのスーパーグローバル](https://www.php.net/manual/en/language.variables.superglobals.php)(`$_SERVER`、`$_ENV`、`$_GET`など)
Expand Down
1 change: 0 additions & 1 deletion docs/pt-br/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ A [opção global](https://caddyserver.com/docs/caddyfile/concepts#global-option
env <chave> <valor> # Define uma variável de ambiente extra para o valor fornecido. Pode ser especificada mais de uma vez para múltiplas variáveis de ambiente.
watch <caminho> # Define o caminho para monitorar alterações em arquivos. Pode ser especificada mais de uma vez para múltiplos caminhos.
name <nome> # Define o nome do worker, usado em logs e métricas. Padrão: caminho absoluto do arquivo do worker.
max_consecutive_failures <num> # Define o número máximo de falhas consecutivas antes do worker ser considerado inoperante. -1 significa que o worker sempre reiniciará. Padrão: 6.
}
}
}
Expand Down
23 changes: 0 additions & 23 deletions docs/pt-br/worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,6 @@ endpoint de reinicialização com uma simples requisição POST como esta:
curl -X POST http://localhost:2019/frankenphp/workers/restart
```

### Falhas de worker

Se um worker script travar com um código de saída diferente de zero, o
FrankenPHP o reiniciará com uma estratégia de backoff exponencial.
Se o worker script permanecer ativo por mais tempo do que o último backoff \* 2,
ele não irá penalizar o worker script e reiniciá-lo novamente.
No entanto, se o worker script continuar a falhar com um código de saída
diferente de zero em um curto período de tempo (por exemplo, com um erro de
digitação em um script), o FrankenPHP travará com o erro:
`too many consecutive failures` (muitas falhas consecutivas).

O número de falhas consecutivas pode ser configurado no seu
[Caddyfile](config.md#caddyfile-config) com a opção `max_consecutive_failures`:

```caddyfile
frankenphp {
worker {
# ...
max_consecutive_failures 10
}
}
```

## Comportamento das superglobais

As
Expand Down
19 changes: 0 additions & 19 deletions docs/worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,6 @@ gracefully via the [Caddy admin API](https://caddyserver.com/docs/api). If the a
curl -X POST http://localhost:2019/frankenphp/workers/restart
```

### Worker Failures

If a worker script crashes with a non-zero exit code, FrankenPHP will restart it with an exponential backoff strategy.
If the worker script stays up longer than the last backoff \* 2,
it will not penalize the worker script and restart it again.
However, if the worker script continues to fail with a non-zero exit code in a short period of time
(for example, having a typo in a script), FrankenPHP will crash with the error: `too many consecutive failures`.

The number of consecutive failures can be configured in your [Caddyfile](config.md#caddyfile-config) with the `max_consecutive_failures` option:

```caddyfile
frankenphp {
worker {
# ...
max_consecutive_failures 10
}
}
```

## Superglobals Behavior

[PHP superglobals](https://www.php.net/manual/en/language.variables.superglobals.php) (`$_SERVER`, `$_ENV`, `$_GET`...)
Expand Down
10 changes: 6 additions & 4 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,12 @@ func testRequestHeaders(t *testing.T, opts *testOptions) {
}

func TestFailingWorker(t *testing.T) {
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
body, _ := testGet("http://example.com/failing-worker.php", handler, t)
assert.Contains(t, body, "ok")
}, &testOptions{workerScript: "failing-worker.php"})
err := frankenphp.Init(
frankenphp.WithLogger(slog.New(slog.NewTextHandler(io.Discard, nil))),
frankenphp.WithWorkers("failing worker", "testdata/failing-worker.php", 4),
frankenphp.WithNumThreads(5),
)
assert.Error(t, err, "should return an immediate error if workers fail on startup")
}

func TestEnv(t *testing.T) {
Expand Down
59 changes: 0 additions & 59 deletions internal/backoff/backoff.go

This file was deleted.

41 changes: 0 additions & 41 deletions internal/backoff/backoff_test.go

This file was deleted.

Loading