Skip to content

Commit 10de327

Browse files
authored
Merge branch 'main' into fix/smaller-static
2 parents 350ca85 + eeb7d1a commit 10de327

55 files changed

Lines changed: 1285 additions & 898 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/docker.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ jobs:
194194
VARIANT: ${{ matrix.variant }}
195195
- name: Upload builder metadata
196196
if: fromJson(needs.prepare.outputs.push)
197-
uses: actions/upload-artifact@v4
197+
uses: actions/upload-artifact@v5
198198
with:
199199
name: metadata-builder-${{ matrix.variant }}-${{ steps.prepare.outputs.sanitized_platform }}
200200
path: /tmp/metadata/builder/*
201201
if-no-files-found: error
202202
retention-days: 1
203203
- name: Upload runner metadata
204204
if: fromJson(needs.prepare.outputs.push)
205-
uses: actions/upload-artifact@v4
205+
uses: actions/upload-artifact@v5
206206
with:
207207
name: metadata-runner-${{ matrix.variant }}-${{ steps.prepare.outputs.sanitized_platform }}
208208
path: /tmp/metadata/runner/*
@@ -234,7 +234,7 @@ jobs:
234234
target: ["builder", "runner"]
235235
steps:
236236
- name: Download metadata
237-
uses: actions/download-artifact@v5
237+
uses: actions/download-artifact@v6
238238
with:
239239
pattern: metadata-${{ matrix.target }}-${{ matrix.variant }}-*
240240
path: /tmp/metadata

.github/workflows/static.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ jobs:
156156
METADATA: ${{ steps.build.outputs.metadata }}
157157
- name: Upload metadata
158158
if: fromJson(needs.prepare.outputs.push) && !matrix.debug && !matrix.mimalloc
159-
uses: actions/upload-artifact@v4
159+
uses: actions/upload-artifact@v5
160160
with:
161161
name: metadata-static-builder-musl-${{ steps.prepare.outputs.sanitized_platform }}
162162
path: /tmp/metadata/*
@@ -174,7 +174,7 @@ jobs:
174174
PLATFORM: ${{ matrix.platform }}
175175
- name: Upload artifact
176176
if: ${{ !fromJson(needs.prepare.outputs.push) }}
177-
uses: actions/upload-artifact@v4
177+
uses: actions/upload-artifact@v5
178178
with:
179179
name: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}${{ matrix.debug && '-debug' || '' }}${{ matrix.mimalloc && '-mimalloc' || '' }}
180180
path: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}${{ matrix.debug && '-debug' || '' }}${{ matrix.mimalloc && '-mimalloc' || '' }}
@@ -266,7 +266,7 @@ jobs:
266266
METADATA: ${{ steps.build.outputs.metadata }}
267267
- name: Upload metadata
268268
if: fromJson(needs.prepare.outputs.push)
269-
uses: actions/upload-artifact@v4
269+
uses: actions/upload-artifact@v5
270270
with:
271271
name: metadata-static-builder-gnu-${{ steps.prepare.outputs.sanitized_platform }}
272272
path: /tmp/metadata-gnu/*
@@ -290,7 +290,7 @@ jobs:
290290
PLATFORM: ${{ matrix.platform }}
291291
- name: Upload artifact
292292
if: ${{ !fromJson(needs.prepare.outputs.push) }}
293-
uses: actions/upload-artifact@v4
293+
uses: actions/upload-artifact@v5
294294
with:
295295
name: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}-gnu-files
296296
path: gh-output/*
@@ -326,13 +326,13 @@ jobs:
326326
if: fromJson(needs.prepare.outputs.push)
327327
steps:
328328
- name: Download metadata
329-
uses: actions/download-artifact@v5
329+
uses: actions/download-artifact@v6
330330
with:
331331
pattern: metadata-static-builder-musl-*
332332
path: /tmp/metadata
333333
merge-multiple: true
334334
- name: Download GNU metadata
335-
uses: actions/download-artifact@v5
335+
uses: actions/download-artifact@v6
336336
with:
337337
pattern: metadata-static-builder-gnu-*
338338
path: /tmp/metadata-gnu
@@ -419,13 +419,19 @@ jobs:
419419
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
420420
RELEASE: ${{ (needs.prepare.outputs.ref || github.ref_type == 'tag') && '1' || '' }}
421421
NO_COMPRESS: ${{ github.event_name == 'pull_request' && '1' || '' }}
422+
- name: Upload logs
423+
if: ${{ failure() }}
424+
uses: actions/upload-artifact@v5
425+
with:
426+
path: dist/static-php-cli/log
427+
name: static-php-cli-log-${{ matrix.platform }}-${{ github.sha }}
422428
- if: needs.prepare.outputs.ref || github.ref_type == 'tag'
423429
uses: actions/attest-build-provenance@v3
424430
with:
425431
subject-path: ${{ github.workspace }}/dist/frankenphp-mac-*
426432
- name: Upload artifact
427433
if: github.ref_type == 'branch'
428-
uses: actions/upload-artifact@v4
434+
uses: actions/upload-artifact@v5
429435
with:
430436
name: frankenphp-mac-${{ matrix.platform }}
431437
path: dist/frankenphp-mac-${{ matrix.platform }}

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
- name: Run integrations tests
8484
run: ./reload_test.sh
8585
- name: Lint Go code
86-
uses: golangci/golangci-lint-action@v8
86+
uses: golangci/golangci-lint-action@v9
8787
if: matrix.php-versions == '8.4'
8888
with:
8989
version: latest

caddy/app.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package caddy
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"log/slog"
78
"path/filepath"
89
"strconv"
910
"strings"
11+
"sync"
1012
"time"
1113

1214
"github.com/caddyserver/caddy/v2"
@@ -18,6 +20,22 @@ import (
1820
"github.com/dunglas/frankenphp/internal/fastabs"
1921
)
2022

23+
var (
24+
options []frankenphp.Option
25+
optionsMU sync.RWMutex
26+
)
27+
28+
// EXPERIMENTAL: RegisterWorkers provides a way for extensions to register frankenphp.Workers
29+
func RegisterWorkers(name, fileName string, num int, wo ...frankenphp.WorkerOption) frankenphp.Workers {
30+
w, opt := frankenphp.WithExtensionWorkers(name, fileName, num, wo...)
31+
32+
optionsMU.Lock()
33+
options = append(options, opt)
34+
optionsMU.Unlock()
35+
36+
return w
37+
}
38+
2139
// FrankenPHPApp represents the global "frankenphp" directive in the Caddyfile
2240
// it's responsible for starting up the global PHP instance and all threads
2341
//
@@ -39,6 +57,7 @@ type FrankenPHPApp struct {
3957
MaxWaitTime time.Duration `json:"max_wait_time,omitempty"`
4058

4159
metrics frankenphp.Metrics
60+
ctx context.Context
4261
logger *slog.Logger
4362
}
4463

@@ -54,6 +73,7 @@ func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
5473

5574
// Provision sets up the module.
5675
func (f *FrankenPHPApp) Provision(ctx caddy.Context) error {
76+
f.ctx = ctx
5777
f.logger = ctx.Slogger()
5878

5979
if httpApp, err := ctx.AppIfConfigured("http"); err == nil {
@@ -111,13 +131,19 @@ func (f *FrankenPHPApp) Start() error {
111131
repl := caddy.NewReplacer()
112132

113133
opts := []frankenphp.Option{
134+
frankenphp.WithContext(f.ctx),
135+
frankenphp.WithLogger(f.logger),
114136
frankenphp.WithNumThreads(f.NumThreads),
115137
frankenphp.WithMaxThreads(f.MaxThreads),
116-
frankenphp.WithLogger(f.logger),
117138
frankenphp.WithMetrics(f.metrics),
118139
frankenphp.WithPhpIni(f.PhpIni),
119140
frankenphp.WithMaxWaitTime(f.MaxWaitTime),
120141
}
142+
143+
optionsMU.RLock()
144+
opts = append(opts, options...)
145+
optionsMU.RUnlock()
146+
121147
for _, w := range append(f.Workers) {
122148
workerOpts := []frankenphp.WorkerOption{
123149
frankenphp.WithWorkerEnv(w.Env),
@@ -137,7 +163,11 @@ func (f *FrankenPHPApp) Start() error {
137163
}
138164

139165
func (f *FrankenPHPApp) Stop() error {
140-
f.logger.Info("FrankenPHP stopped 🐘")
166+
ctx := caddy.ActiveContext()
167+
168+
if f.logger.Enabled(caddy.ActiveContext(), slog.LevelInfo) {
169+
f.logger.LogAttrs(ctx, slog.LevelInfo, "FrankenPHP stopped 🐘")
170+
}
141171

142172
// attempt a graceful shutdown if caddy is exiting
143173
// note: Exiting() is currently marked as 'experimental'
@@ -151,6 +181,10 @@ func (f *FrankenPHPApp) Stop() error {
151181
f.NumThreads = 0
152182
f.MaxWaitTime = 0
153183

184+
optionsMU.Lock()
185+
options = nil
186+
optionsMU.Unlock()
187+
154188
return nil
155189
}
156190

caddy/caddy_test.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@ func TestGlobalAndModuleWorker(t *testing.T) {
168168
wg.Wait()
169169
}
170170

171+
func TestModuleWorkerInheritsEnv(t *testing.T) {
172+
tester := caddytest.NewTester(t)
173+
tester.InitServer(`
174+
{
175+
skip_install_trust
176+
admin localhost:2999
177+
}
178+
179+
http://localhost:`+testPort+` {
180+
route {
181+
php {
182+
root ../testdata
183+
env APP_ENV inherit_this
184+
worker worker-with-env.php
185+
}
186+
}
187+
}
188+
`, "caddyfile")
189+
190+
tester.AssertGetResponse("http://localhost:"+testPort+"/worker-with-env.php", http.StatusOK, "Worker has APP_ENV=inherit_this")
191+
}
192+
171193
func TestNamedModuleWorkers(t *testing.T) {
172194
var wg sync.WaitGroup
173195
testPortNum, _ := strconv.Atoi(testPort)
@@ -943,15 +965,15 @@ func TestMaxWaitTime(t *testing.T) {
943965
for range 10 {
944966
go func() {
945967
statusCode := getStatusCode("http://localhost:"+testPort+"/sleep.php?sleep=10", t)
946-
if statusCode == http.StatusGatewayTimeout {
968+
if statusCode == http.StatusServiceUnavailable {
947969
success.Store(true)
948970
}
949971
wg.Done()
950972
}()
951973
}
952974
wg.Wait()
953975

954-
require.True(t, success.Load(), "At least one request should have failed with a 504 Gateway Timeout status")
976+
require.True(t, success.Load(), "At least one request should have failed with a 503 Service Unavailable status")
955977
}
956978

957979
func TestMaxWaitTimeWorker(t *testing.T) {
@@ -990,23 +1012,26 @@ func TestMaxWaitTimeWorker(t *testing.T) {
9901012
for range 10 {
9911013
go func() {
9921014
statusCode := getStatusCode("http://localhost:"+testPort+"/sleep.php?sleep=10&iteration=1", t)
993-
if statusCode == http.StatusGatewayTimeout {
1015+
if statusCode == http.StatusServiceUnavailable {
9941016
success.Store(true)
9951017
}
9961018
wg.Done()
9971019
}()
9981020
}
9991021
wg.Wait()
1000-
require.True(t, success.Load(), "At least one request should have failed with a 504 Gateway Timeout status")
1022+
require.True(t, success.Load(), "At least one request should have failed with a 503 Service Unavailable status")
10011023

10021024
// Fetch metrics
10031025
resp, err := http.Get("http://localhost:2999/metrics")
10041026
require.NoError(t, err, "failed to fetch metrics")
1005-
defer resp.Body.Close()
1027+
t.Cleanup(func() {
1028+
require.NoError(t, resp.Body.Close())
1029+
})
10061030

10071031
// Read and parse metrics
10081032
metrics := new(bytes.Buffer)
10091033
_, err = metrics.ReadFrom(resp.Body)
1034+
require.NoError(t, err)
10101035

10111036
expectedMetrics := `
10121037
# TYPE frankenphp_worker_queue_depth gauge

0 commit comments

Comments
 (0)