Skip to content

Commit 0d0f336

Browse files
committed
Merge remote-tracking branch 'origin/main' into enhancement/optional-root
2 parents 824f93f + 006f37f commit 0d0f336

23 files changed

Lines changed: 812 additions & 254 deletions

CONTRIBUTING.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,60 +90,60 @@ curl -v http://127.0.0.1:8080/phpinfo.php
9090

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

93-
```powershell
94-
git config --global core.autocrlf false
95-
git config --global core.eol lf
96-
```
93+
```powershell
94+
git config --global core.autocrlf false
95+
git config --global core.eol lf
96+
```
9797

9898
2. Install Visual Studio, Git, and Go:
9999

100-
```powershell
101-
winget install -e --id Microsoft.VisualStudio.2022.Community --override "--passive --wait --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --includeRecommended"
102-
winget install -e --id GoLang.Go
103-
winget install -e --id Git.Git
104-
```
100+
```powershell
101+
winget install -e --id Microsoft.VisualStudio.2022.Community --override "--passive --wait --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --includeRecommended"
102+
winget install -e --id GoLang.Go
103+
winget install -e --id Git.Git
104+
```
105105

106106
3. Install vcpkg:
107107

108-
```powershell
109-
cd C:\
110-
git clone https://github.com/microsoft/vcpkg
111-
.\vcpkg\bootstrap-vcpkg.bat
112-
```
108+
```powershell
109+
cd C:\
110+
git clone https://github.com/microsoft/vcpkg
111+
.\vcpkg\bootstrap-vcpkg.bat
112+
```
113113

114114
4. [Download the latest version of the watcher library for Windows](https://github.com/e-dant/watcher/releases) and extract it to a directory named `C:\watcher`
115115
5. [Download the latest **Thread Safe** version of PHP and of the PHP SDK for Windows](https://windows.php.net/download/), extract them in directories named `C:\php` and `C:\php-devel`
116116
6. Clone the FrankenPHP Git repository:
117117

118-
```powershell
119-
git clone https://github.com/php/frankenphp C:\frankenphp
120-
cd C:\frankenphp
121-
```
118+
```powershell
119+
git clone https://github.com/php/frankenphp C:\frankenphp
120+
cd C:\frankenphp
121+
```
122122

123123
7. Install the dependencies:
124124

125-
```powershell
126-
C:\vcpkg\vcpkg.exe install
127-
```
125+
```powershell
126+
C:\vcpkg\vcpkg.exe install
127+
```
128128

129129
8. Configure the needed environment variables (PowerShell):
130130

131-
```powershell
132-
$env:PATH += ';C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\bin'
133-
$env:CC = 'clang'
134-
$env:CXX = 'clang++'
135-
$env:CGO_CFLAGS = "-O0 -g -IC:\frankenphp\vcpkg_installed\x64-windows\include -IC:\watcher -IC:\php-devel\include -IC:\php-devel\include\main -IC:\php-devel\include\TSRM -IC:\php-devel\include\Zend -IC:\php-devel\include\ext"
136-
$env:CGO_LDFLAGS = '-LC:\frankenphp\vcpkg_installed\x64-windows\lib -lbrotlienc -LC:\watcher -llibwatcher-c -LC:\php -LC:\php-devel\lib -lphp8ts -lphp8embed'
137-
```
131+
```powershell
132+
$env:PATH += ';C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\bin'
133+
$env:CC = 'clang'
134+
$env:CXX = 'clang++'
135+
$env:CGO_CFLAGS = "-O0 -g -IC:\frankenphp\vcpkg_installed\x64-windows\include -IC:\watcher -IC:\php-devel\include -IC:\php-devel\include\main -IC:\php-devel\include\TSRM -IC:\php-devel\include\Zend -IC:\php-devel\include\ext"
136+
$env:CGO_LDFLAGS = '-LC:\frankenphp\vcpkg_installed\x64-windows\lib -lbrotlienc -LC:\watcher -llibwatcher-c -LC:\php -LC:\php-devel\lib -lphp8ts -lphp8embed'
137+
```
138138

139139
9. Run the tests:
140140

141-
```powershell
142-
go test -race -ldflags '-extldflags="-fuse-ld=lld"' ./...
143-
cd caddy
144-
go test -race -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx ./...
145-
cd ..
146-
```
141+
```powershell
142+
go test -race -ldflags '-extldflags="-fuse-ld=lld"' ./...
143+
cd caddy
144+
go test -race -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx ./...
145+
cd ..
146+
```
147147

148148
10. Build the binary:
149149

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ Our maintainers offer apk packages for all systems using `apk`. To install, run:
9090
VERSION=85 # 82-85 available
9191
echo "https://pkg.henderkes.com/api/packages/${VERSION}/alpine/main/php-zts" | sudo tee -a /etc/apk/repositories
9292
KEYFILE=$(curl -sJOw '%{filename_effective}' https://pkg.henderkes.com/api/packages/${VERSION}/alpine/key)
93-
sudo mv ${KEYFILE} /etc/apk/keys/ &&
94-
sudo apk update &&
93+
sudo mv ${KEYFILE} /etc/apk/keys/ &&
94+
sudo apk update &&
9595
sudo apk add frankenphp
9696
```
9797

@@ -170,6 +170,7 @@ Go to `https://localhost`, and enjoy!
170170
- [Compile from sources](https://frankenphp.dev/docs/compile/)
171171
- [Monitoring FrankenPHP](https://frankenphp.dev/docs/metrics/)
172172
- [WordPress integration](https://frankenphp.dev/docs/wordpress/)
173+
- [Symfony integration](https://frankenphp.dev/docs/symfony/)
173174
- [Laravel integration](https://frankenphp.dev/docs/laravel/)
174175
- [Known issues](https://frankenphp.dev/docs/known-issues/)
175176
- [Demo app (Symfony) and benchmarks](https://github.com/dunglas/frankenphp-demo)
@@ -178,7 +179,7 @@ Go to `https://localhost`, and enjoy!
178179

179180
## Examples and Skeletons
180181

181-
- [Symfony](https://github.com/dunglas/symfony-docker)
182+
- [Symfony](https://frankenphp.dev/docs/symfony/)
182183
- [API Platform](https://api-platform.com/docs/symfony)
183184
- [Laravel](https://frankenphp.dev/docs/laravel/)
184185
- [Sulu](https://sulu.io/blog/running-sulu-with-frankenphp)

caddy/admin_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,46 @@ func TestShowTheCorrectThreadDebugStatus(t *testing.T) {
8282
assert.Len(t, debugState.ThreadDebugStates, 3)
8383
}
8484

85+
func TestThreadDebugStateMetricsAfterRequests(t *testing.T) {
86+
tester := caddytest.NewTester(t)
87+
tester.InitServer(`
88+
{
89+
skip_install_trust
90+
admin localhost:2999
91+
http_port `+testPort+`
92+
93+
frankenphp {
94+
num_threads 2
95+
worker ../testdata/worker-with-counter.php 1
96+
}
97+
}
98+
99+
localhost:`+testPort+` {
100+
route {
101+
root ../testdata
102+
rewrite worker-with-counter.php
103+
php
104+
}
105+
}
106+
`, "caddyfile")
107+
108+
// make a few requests so counters are populated
109+
tester.AssertGetResponse("http://localhost:"+testPort+"/", http.StatusOK, "requests:1")
110+
tester.AssertGetResponse("http://localhost:"+testPort+"/", http.StatusOK, "requests:2")
111+
tester.AssertGetResponse("http://localhost:"+testPort+"/", http.StatusOK, "requests:3")
112+
113+
debugState := getDebugState(t, tester)
114+
115+
hasRequestCount := false
116+
for _, ts := range debugState.ThreadDebugStates {
117+
if ts.RequestCount > 0 {
118+
hasRequestCount = true
119+
assert.Greater(t, ts.MemoryUsage, int64(0), "thread %d (%s) should report memory usage", ts.Index, ts.Name)
120+
}
121+
}
122+
assert.True(t, hasRequestCount, "at least one thread should have RequestCount > 0 after serving requests")
123+
}
124+
85125
func TestAutoScaleWorkerThreads(t *testing.T) {
86126
wg := sync.WaitGroup{}
87127
maxTries := 10

caddy/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require github.com/smallstep/go-attestation v0.4.4-0.20241119153605-2306d5b464ca
2525

2626
require (
2727
cel.dev/expr v0.25.1 // indirect
28-
cloud.google.com/go/auth v0.18.2 // indirect
28+
cloud.google.com/go/auth v0.19.0 // indirect
2929
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
3030
cloud.google.com/go/compute/metadata v0.9.0 // indirect
3131
dario.cat/mergo v1.0.2 // indirect
@@ -93,7 +93,7 @@ require (
9393
github.com/google/s2a-go v0.1.9 // indirect
9494
github.com/google/uuid v1.6.0 // indirect
9595
github.com/googleapis/enterprise-certificate-proxy v0.3.14 // indirect
96-
github.com/googleapis/gax-go/v2 v2.19.0 // indirect
96+
github.com/googleapis/gax-go/v2 v2.20.0 // indirect
9797
github.com/gorilla/handlers v1.5.2 // indirect
9898
github.com/gorilla/mux v1.8.1 // indirect
9999
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
@@ -125,7 +125,7 @@ require (
125125
github.com/oasdiff/yaml v0.0.1 // indirect
126126
github.com/oasdiff/yaml3 v0.0.1 // indirect
127127
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
128-
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
128+
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
129129
github.com/perimeterx/marshmallow v1.1.5 // indirect
130130
github.com/pires/go-proxyproto v0.11.0 // indirect
131131
github.com/pkg/errors v0.9.1 // indirect
@@ -218,7 +218,7 @@ require (
218218
golang.org/x/text v0.35.0 // indirect
219219
golang.org/x/time v0.15.0 // indirect
220220
golang.org/x/tools v0.43.0 // indirect
221-
google.golang.org/api v0.272.0 // indirect
221+
google.golang.org/api v0.273.0 // indirect
222222
google.golang.org/genproto/googleapis/api v0.0.0-20260319201613-d00831a3d3e7 // indirect
223223
google.golang.org/genproto/googleapis/rpc v0.0.0-20260319201613-d00831a3d3e7 // indirect
224224
google.golang.org/grpc v1.79.3 // indirect

caddy/go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cel.dev/expr v0.25.1 h1:1KrZg61W6TWSxuNZ37Xy49ps13NUovb66QLprthtwi4=
22
cel.dev/expr v0.25.1/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4=
33
cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE=
44
cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU=
5-
cloud.google.com/go/auth v0.18.2 h1:+Nbt5Ev0xEqxlNjd6c+yYUeosQ5TtEUaNcN/3FozlaM=
6-
cloud.google.com/go/auth v0.18.2/go.mod h1:xD+oY7gcahcu7G2SG2DsBerfFxgPAJz17zz2joOFF3M=
5+
cloud.google.com/go/auth v0.19.0 h1:DGYwtbcsGsT1ywuxsIoWi1u/vlks0moIblQHgSDgQkQ=
6+
cloud.google.com/go/auth v0.19.0/go.mod h1:2Aph7BT2KnaSFOM0JDPyiYgNh6PL9vGMiP8CUIXZ+IY=
77
cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc=
88
cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c=
99
cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=
@@ -238,8 +238,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
238238
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
239239
github.com/googleapis/enterprise-certificate-proxy v0.3.14 h1:yh8ncqsbUY4shRD5dA6RlzjJaT4hi3kII+zYw8wmLb8=
240240
github.com/googleapis/enterprise-certificate-proxy v0.3.14/go.mod h1:vqVt9yG9480NtzREnTlmGSBmFrA+bzb0yl0TxoBQXOg=
241-
github.com/googleapis/gax-go/v2 v2.19.0 h1:fYQaUOiGwll0cGj7jmHT/0nPlcrZDFPrZRhTsoCr8hE=
242-
github.com/googleapis/gax-go/v2 v2.19.0/go.mod h1:w2ROXVdfGEVFXzmlciUU4EdjHgWvB5h2n6x/8XSTTJA=
241+
github.com/googleapis/gax-go/v2 v2.20.0 h1:NIKVuLhDlIV74muWlsMM4CcQZqN6JJ20Qcxd9YMuYcs=
242+
github.com/googleapis/gax-go/v2 v2.20.0/go.mod h1:But/NJU6TnZsrLai/xBAQLLz+Hc7fHZJt/hsCz3Fih4=
243243
github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE=
244244
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
245245
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
@@ -326,8 +326,8 @@ github.com/oasdiff/yaml3 v0.0.1/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbG
326326
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
327327
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
328328
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
329-
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
330-
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
329+
github.com/pelletier/go-toml/v2 v2.3.0 h1:k59bC/lIZREW0/iVaQR8nDHxVq8OVlIzYCOJf421CaM=
330+
github.com/pelletier/go-toml/v2 v2.3.0/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
331331
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
332332
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
333333
github.com/peterbourgon/diskv/v3 v3.0.1 h1:x06SQA46+PKIUftmEujdwSEpIx8kR+M9eLYsUxeYveU=
@@ -646,10 +646,10 @@ golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0
646646
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
647647
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
648648
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
649-
google.golang.org/api v0.272.0 h1:eLUQZGnAS3OHn31URRf9sAmRk3w2JjMx37d2k8AjJmA=
650-
google.golang.org/api v0.272.0/go.mod h1:wKjowi5LNJc5qarNvDCvNQBn3rVK8nSy6jg2SwRwzIA=
651-
google.golang.org/genproto v0.0.0-20260316180232-0b37fe3546d5 h1:JNfk58HZ8lfmXbYK2vx/UvsqIL59TzByCxPIX4TDmsE=
652-
google.golang.org/genproto v0.0.0-20260316180232-0b37fe3546d5/go.mod h1:x5julN69+ED4PcFk/XWayw35O0lf/nGa4aNgODCmNmw=
649+
google.golang.org/api v0.273.0 h1:r/Bcv36Xa/te1ugaN1kdJ5LoA5Wj/cL+a4gj6FiPBjQ=
650+
google.golang.org/api v0.273.0/go.mod h1:JbAt7mF+XVmWu6xNP8/+CTiGH30ofmCmk9nM8d8fHew=
651+
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 h1:XzmzkmB14QhVhgnawEVsOn6OFsnpyxNPRY9QV01dNB0=
652+
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7/go.mod h1:L43LFes82YgSonw6iTXTxXUX1OlULt4AQtkik4ULL/I=
653653
google.golang.org/genproto/googleapis/api v0.0.0-20260319201613-d00831a3d3e7 h1:41r6JMbpzBMen0R/4TZeeAmGXSJC7DftGINUodzTkPI=
654654
google.golang.org/genproto/googleapis/api v0.0.0-20260319201613-d00831a3d3e7/go.mod h1:EIQZ5bFCfRQDV4MhRle7+OgjNtZ6P1PiZBgAKuxXu/Y=
655655
google.golang.org/genproto/googleapis/rpc v0.0.0-20260319201613-d00831a3d3e7 h1:ndE4FoJqsIceKP2oYSnUZqhTdYufCYYkqwtFzfrhI7w=

debugstate.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package frankenphp
22

3+
// #include "frankenphp.h"
4+
import "C"
35
import (
46
"github.com/dunglas/frankenphp/internal/state"
57
)
@@ -12,6 +14,11 @@ type ThreadDebugState struct {
1214
IsWaiting bool
1315
IsBusy bool
1416
WaitingSinceMilliseconds int64
17+
CurrentURI string
18+
CurrentMethod string
19+
RequestStartedAt int64
20+
RequestCount int64
21+
MemoryUsage int64
1522
}
1623

1724
// EXPERIMENTAL: FrankenPHPDebugState prints the state of all PHP threads - debugging purposes only
@@ -39,12 +46,51 @@ func DebugState() FrankenPHPDebugState {
3946

4047
// threadDebugState creates a small jsonable status message for debugging purposes
4148
func threadDebugState(thread *phpThread) ThreadDebugState {
42-
return ThreadDebugState{
49+
isBusy := !thread.state.IsInWaitingState()
50+
51+
s := ThreadDebugState{
4352
Index: thread.threadIndex,
4453
Name: thread.name(),
4554
State: thread.state.Name(),
4655
IsWaiting: thread.state.IsInWaitingState(),
47-
IsBusy: !thread.state.IsInWaitingState(),
56+
IsBusy: isBusy,
4857
WaitingSinceMilliseconds: thread.state.WaitTime(),
4958
}
59+
60+
s.RequestCount = thread.requestCount.Load()
61+
s.MemoryUsage = int64(C.frankenphp_get_thread_memory_usage(C.uintptr_t(thread.threadIndex)))
62+
63+
if !isBusy {
64+
return s
65+
}
66+
67+
thread.handlerMu.RLock()
68+
handler := thread.handler
69+
thread.handlerMu.RUnlock()
70+
71+
if handler == nil {
72+
return s
73+
}
74+
75+
thread.contextMu.RLock()
76+
defer thread.contextMu.RUnlock()
77+
78+
fc := handler.frankenPHPContext()
79+
if fc == nil || fc.request == nil || fc.responseWriter == nil {
80+
return s
81+
}
82+
83+
if fc.originalRequest == nil {
84+
s.CurrentURI = fc.requestURI
85+
s.CurrentMethod = fc.request.Method
86+
} else {
87+
s.CurrentURI = fc.originalRequest.URL.RequestURI()
88+
s.CurrentMethod = fc.originalRequest.Method
89+
}
90+
91+
if !fc.startedAt.IsZero() {
92+
s.RequestStartedAt = fc.startedAt.UnixMilli()
93+
}
94+
95+
return s
5096
}

0 commit comments

Comments
 (0)