Skip to content

Define domain specific workers in php_server and php blocks #1509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a165c4e
add module (php_server directive) based workers
henderkes Apr 17, 2025
61bbef4
refactor moduleID to uintptr for faster comparisons
henderkes Apr 18, 2025
7fffbc2
let workers inherit environment variables and root from php_server
henderkes Apr 18, 2025
60c3e12
caddy can shift FrankenPHPModules in memory for some godforsaken reas…
henderkes Apr 18, 2025
97913f8
remove debugging statement
henderkes Apr 18, 2025
a22cd19
fix tests
henderkes Apr 18, 2025
a4016df
refactor moduleID to uint64 for faster comparisons
henderkes Apr 19, 2025
a21d3f4
actually allow multiple workers per script filename
henderkes Apr 19, 2025
7718a8e
remove logging
henderkes Apr 19, 2025
c7172d2
utility function
henderkes Apr 19, 2025
f955187
reuse existing worker with same filename and environment when calling…
henderkes Apr 19, 2025
e362fd3
no cleanup happens between tests, so restore old global worker overwr…
henderkes Apr 19, 2025
00d819f
add test, use getWorker(ForContext) function in frankenphp.go as well
henderkes Apr 20, 2025
bc48bdd
bring error on second global worker with the same filename again
henderkes Apr 20, 2025
0b22d51
refactor to using name instead of moduleID
henderkes Apr 21, 2025
c6bcacf
nicer name
henderkes Apr 21, 2025
53795c7
nicer name
henderkes Apr 21, 2025
958537e
add more tests
henderkes Apr 21, 2025
6c39229
remove test case already covered by previous test
henderkes Apr 21, 2025
e19b7b2
revert back to single variable, moduleIDs no longer relevant
henderkes Apr 21, 2025
2ff18ba
update comment
henderkes Apr 21, 2025
5fc1edf
figure out the worker to use in FrankenPHPModule::ServeHTTP
henderkes Apr 22, 2025
2c2f677
add caddy/config_tests, add --retry 5 to download
henderkes Apr 22, 2025
3b15199
add caddy/config_tests
henderkes Apr 22, 2025
af18d04
sum up logic a bit, put worker thread addition into moduleWorkers par…
henderkes Apr 22, 2025
dd5dc9b
implement suggestions as far as possible
henderkes Apr 23, 2025
c4937ac
fixup
henderkes Apr 23, 2025
401d25d
remove tags
henderkes Apr 23, 2025
a444361
feat: download the mostly static binary when possible (#1467)
dunglas Apr 18, 2025
6ebea60
docs: remove wildcard matcher from root directive (#1513)
IndraGunawan Apr 22, 2025
fb4e262
docs: update README with additional documentation links
Rom1Bastide Apr 22, 2025
9ff4ee2
ci: combine dependabot updates for one group to 1 pull-request
IndraGunawan Apr 22, 2025
e648532
feat: compatibility with libphp.dylib on macOS
dunglas Apr 22, 2025
af74391
feat: upgrade to Caddy 2.10
dunglas Apr 22, 2025
34f3b25
feat: upgrade to Caddy 2.10
dunglas Apr 22, 2025
9929383
chore: run prettier
dunglas Apr 22, 2025
0bbd4c6
fix: build-static.sh consecutive builds (#1496)
henderkes Apr 23, 2025
c96f53c
chore: update Go and toolchain version (#1526)
IndraGunawan Apr 23, 2025
26360fb
apply suggestions one be one - scriptpath only
henderkes Apr 24, 2025
39430e8
merge main into workers
henderkes Apr 24, 2025
801e71c
generate unique worker names by filename and number
henderkes Apr 24, 2025
6650045
support worker config from embedded apps
henderkes Apr 24, 2025
53e7bc0
rename back to make sure we don't accidentally add FrankenPHPApp work…
henderkes Apr 24, 2025
78be813
fix test after changing error message
henderkes Apr 24, 2025
4cc8893
use 🧩 for module workers
henderkes Apr 24, 2025
1c414ce
use 🌍 for global workers :)
henderkes Apr 24, 2025
9ccac16
Merge branch 'main' into workers
henderkes Apr 26, 2025
3f8f5ec
revert 1c414cebbc4380b26c4ac46a8662f88bd807aa09
henderkes Apr 26, 2025
a6596c7
revert 4cc8893cedc8a2c9e2195ca0e83e8e9cc359e136
henderkes Apr 27, 2025
d5d2eb3
apply suggestions
henderkes Apr 29, 2025
6f27895
add dynamic config loading test of module worker
henderkes Apr 29, 2025
a6b840f
Merge remote-tracking branch 'dunglas/main' into workers
henderkes Apr 29, 2025
877a6ce
fix test
henderkes Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions build-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ if [ -z "${SPC_OPT_BUILD_ARGS}" ]; then
fi
# init spc download additional args
if [ -z "${SPC_OPT_DOWNLOAD_ARGS}" ]; then
SPC_OPT_DOWNLOAD_ARGS="--ignore-cache-sources=php-src --retry 5"
if [ "${SPC_LIBC}" = "musl" ]; then
SPC_OPT_DOWNLOAD_ARGS="--prefer-pre-built --ignore-cache-sources=php-src"
else
SPC_OPT_DOWNLOAD_ARGS="--ignore-cache-sources=php-src"
SPC_OPT_DOWNLOAD_ARGS="${SPC_OPT_DOWNLOAD_ARGS} --prefer-pre-built"
fi
fi
# if we need debug symbols, disable strip
Expand Down
82 changes: 82 additions & 0 deletions caddy/admin_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package caddy_test

import (
"bytes"
"encoding/json"
"fmt"
"github.com/dunglas/frankenphp/internal/fastabs"
"io"
"net/http"
"sync"
Expand Down Expand Up @@ -213,3 +216,82 @@ func getDebugState(t *testing.T, tester *caddytest.Tester) frankenphp.FrankenPHP

return debugStates
}

func TestAddModuleWorkerViaAdminApi(t *testing.T) {
// Initialize a server with admin API enabled
tester := caddytest.NewTester(t)
tester.InitServer(`
{
skip_install_trust
admin localhost:2999
http_port `+testPort+`

frankenphp
}

localhost:`+testPort+` {
route {
root ../testdata
php
}
}
`, "caddyfile")

// Get initial debug state to check number of workers
initialDebugState := getDebugState(t, tester)
initialWorkerCount := 0
for _, thread := range initialDebugState.ThreadDebugStates {
if thread.Name != "" && thread.Name != "ready" {
initialWorkerCount++
}
}

// Create a Caddyfile configuration with a module worker
workerConfig := `
{
skip_install_trust
admin localhost:2999
http_port ` + testPort + `

frankenphp
}

localhost:` + testPort + ` {
route {
root ../testdata
php {
worker ../testdata/worker-with-counter.php 1
}
}
}
`

// Send the configuration to the admin API
adminUrl := "http://localhost:2999/load"
r, err := http.NewRequest("POST", adminUrl, bytes.NewBufferString(workerConfig))
assert.NoError(t, err)
r.Header.Set("Content-Type", "text/caddyfile")
resp := tester.AssertResponseCode(r, http.StatusOK)
defer resp.Body.Close()

// Get the updated debug state to check if the worker was added
updatedDebugState := getDebugState(t, tester)
updatedWorkerCount := 0
workerFound := false
filename, _ := fastabs.FastAbs("../testdata/worker-with-counter.php")
for _, thread := range updatedDebugState.ThreadDebugStates {
if thread.Name != "" && thread.Name != "ready" {
updatedWorkerCount++
if thread.Name == "Worker PHP Thread - "+filename {
workerFound = true
}
}
}

// Assert that the worker was added
assert.Greater(t, updatedWorkerCount, initialWorkerCount, "Worker count should have increased")
assert.True(t, workerFound, fmt.Sprintf("Worker with name %q should be found", "Worker PHP Thread - "+filename))

// Make a request to the worker to verify it's working
tester.AssertGetResponse("http://localhost:"+testPort+"/worker-with-counter.php", http.StatusOK, "requests:1")
}
Loading