Skip to content

Commit

Permalink
Merge branch 'main' into perf/optimized-request-headers
Browse files Browse the repository at this point in the history
# Conflicts:
#	frankenphp.c
  • Loading branch information
Alliballibaba2 committed Jan 21, 2025
2 parents f357ebe + ece420c commit f6e1851
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func TestAllDefinedServerVars(t *testing.T) {
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: 14", // maliciously set to 14
"Special-Chars: <%00>",
"Host: Malicous Host",
"Host: Malicious Host",
"X-Empty-Header:",
},
bytes.NewBufferString("foo=bar"),
Expand Down
2 changes: 1 addition & 1 deletion caddy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/caddyserver/caddy/v2 v2.9.1
github.com/caddyserver/certmagic v0.21.6
github.com/dunglas/caddy-cbrotli v1.0.0
github.com/dunglas/frankenphp v1.4.0
github.com/dunglas/frankenphp v1.4.1
github.com/dunglas/mercure/caddy v0.18.1
github.com/dunglas/vulcain/caddy v1.1.1
github.com/prometheus/client_golang v1.20.5
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FROM dunglas/frankenphp
# Production:
RUN cp $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini

# Or developement:
# Or development:
RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini
```

Expand Down
2 changes: 1 addition & 1 deletion docs/production.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Refer to "[Building Custom Docker Image](docker.md)" for more details and option
and to learn how to customize the configuration, install PHP extensions and Caddy modules.

If your project uses Composer,
be sure to include it in the Docker image and to install your depedencies.
be sure to include it in the Docker image and to install your dependencies.

Then, add a `compose.yaml` file:

Expand Down
5 changes: 1 addition & 4 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ static void frankenphp_worker_request_shutdown() {
zend_end_try();

zend_set_memory_limit(PG(memory_limit));
/* TODO: remove next line when https://github.com/php/php-src/pull/14499 will
* be available */
SG(rfc1867_uploaded_files) = NULL;
}

PHPAPI void get_full_env(zval *track_vars_array) {
Expand Down Expand Up @@ -434,7 +431,7 @@ PHP_FUNCTION(frankenphp_handle_request) {
}

/*
* If an exception occured, print the message to the client before
* If an exception occurred, print the message to the client before
* closing the connection
*/
if (EG(exception)) {
Expand Down
14 changes: 7 additions & 7 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// In all tests, headers added to requests are copied on the heap using strings.Clone.
// This was originally a workaround for https://github.com/golang/go/issues/65286#issuecomment-1920087884 (fixed in Go 1.22),
// but this allows to catch panics occuring in real life but not when the string is in the internal binary memory.
// but this allows to catch panics occurring in real life but not when the string is in the internal binary memory.

package frankenphp_test

Expand Down Expand Up @@ -41,7 +41,7 @@ type testOptions struct {
watch []string
nbWorkers int
env map[string]string
nbParrallelRequests int
nbParallelRequests int
realServer bool
logger *zap.Logger
initOpts []frankenphp.Option
Expand All @@ -51,8 +51,8 @@ func runTest(t *testing.T, test func(func(http.ResponseWriter, *http.Request), *
if opts == nil {
opts = &testOptions{}
}
if opts.nbParrallelRequests == 0 {
opts.nbParrallelRequests = 100
if opts.nbParallelRequests == 0 {
opts.nbParallelRequests = 100
}

cwd, _ := os.Getwd()
Expand Down Expand Up @@ -87,8 +87,8 @@ func runTest(t *testing.T, test func(func(http.ResponseWriter, *http.Request), *
}

var wg sync.WaitGroup
wg.Add(opts.nbParrallelRequests)
for i := 0; i < opts.nbParrallelRequests; i++ {
wg.Add(opts.nbParallelRequests)
for i := 0; i < opts.nbParallelRequests; i++ {
go func(i int) {
test(handler, ts, i)
wg.Done()
Expand Down Expand Up @@ -868,7 +868,7 @@ func BenchmarkServerSuperGlobal(b *testing.B) {
cwd, _ := os.Getwd()
testDataDir := cwd + "/testdata/"

// Mimicks headers of a request sent by Firefox to GitHub
// Mimics headers of a request sent by Firefox to GitHub
headers := http.Header{}
headers.Add(strings.Clone("Accept"), strings.Clone("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"))
headers.Add(strings.Clone("Accept-Encoding"), strings.Clone("gzip, deflate, br"))
Expand Down
4 changes: 2 additions & 2 deletions watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestWorkersShouldReloadOnMatchingPattern(t *testing.T) {
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
requestBodyHasReset := pollForWorkerReset(t, handler, maxTimesToPollForChanges)
assert.True(t, requestBodyHasReset)
}, &testOptions{nbParrallelRequests: 1, nbWorkers: 1, workerScript: "worker-with-watcher.php", watch: watch})
}, &testOptions{nbParallelRequests: 1, nbWorkers: 1, workerScript: "worker-with-watcher.php", watch: watch})
}

func TestWorkersShouldNotReloadOnExcludingPattern(t *testing.T) {
Expand All @@ -38,7 +38,7 @@ func TestWorkersShouldNotReloadOnExcludingPattern(t *testing.T) {
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
requestBodyHasReset := pollForWorkerReset(t, handler, minTimesToPollForChanges)
assert.False(t, requestBodyHasReset)
}, &testOptions{nbParrallelRequests: 1, nbWorkers: 1, workerScript: "worker-with-watcher.php", watch: watch})
}, &testOptions{nbParallelRequests: 1, nbWorkers: 1, workerScript: "worker-with-watcher.php", watch: watch})
}

func fetchBody(method string, url string, handler func(http.ResponseWriter, *http.Request)) string {
Expand Down
8 changes: 4 additions & 4 deletions worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func TestWorker(t *testing.T) {
body2, _ := io.ReadAll(resp2.Body)

assert.Contains(t, string(body2), fmt.Sprintf("Requests handled: %d", i*2+1))
}, &testOptions{workerScript: "worker.php", nbWorkers: 1, nbParrallelRequests: 1})
}, &testOptions{workerScript: "worker.php", nbWorkers: 1, nbParallelRequests: 1})
}

func TestWorkerDie(t *testing.T) {
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
req := httptest.NewRequest("GET", "http://example.com/die.php", nil)
w := httptest.NewRecorder()
handler(w, req)
}, &testOptions{workerScript: "die.php", nbWorkers: 1, nbParrallelRequests: 10})
}, &testOptions{workerScript: "die.php", nbWorkers: 1, nbParallelRequests: 10})
}

func TestNonWorkerModeAlwaysWorks(t *testing.T) {
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestWorkerEnv(t *testing.T) {
body, _ := io.ReadAll(resp.Body)

assert.Equal(t, fmt.Sprintf("bar%d", i), string(body))
}, &testOptions{workerScript: "worker-env.php", nbWorkers: 1, env: map[string]string{"FOO": "bar"}, nbParrallelRequests: 10})
}, &testOptions{workerScript: "worker-env.php", nbWorkers: 1, env: map[string]string{"FOO": "bar"}, nbParallelRequests: 10})
}

func TestWorkerGetOpt(t *testing.T) {
Expand Down Expand Up @@ -150,5 +150,5 @@ func TestWorkerHasOSEnvironmentVariableInSERVER(t *testing.T) {

assert.Contains(t, string(body), "CUSTOM_OS_ENV_VARIABLE")
assert.Contains(t, string(body), "custom_env_variable_value")
}, &testOptions{workerScript: "worker.php", nbWorkers: 1, nbParrallelRequests: 1})
}, &testOptions{workerScript: "worker.php", nbWorkers: 1, nbParallelRequests: 1})
}

0 comments on commit f6e1851

Please sign in to comment.