Skip to content

Commit

Permalink
Adds php.ini override test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alliballibaba2 committed Jan 10, 2025
1 parent 936556b commit 6758903
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
39 changes: 39 additions & 0 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,42 @@ func TestAllDefinedServerVars(t *testing.T) {
expectedBody,
)
}

func TestPHPIniOverride(t *testing.T) {
tester := caddytest.NewTester(t)
tester.InitServer(`
{
skip_install_trust
admin localhost:2999
http_port `+testPort+`
frankenphp {
num_threads 2
worker ../testdata/ini.php 1
php_ini max_execution_time 100
php_ini memory_limit 10000000
}
}
localhost:`+testPort+` {
route {
root ../testdata
php
}
}
`, "caddyfile")

// test twice to ensure the ini setting is not lost
for i := 0; i < 2; i++ {
tester.AssertGetResponse(
"http://localhost:"+testPort+"/ini.php?key=max_execution_time",
http.StatusOK,
"max_execution_time:100",
)
tester.AssertGetResponse(
"http://localhost:"+testPort+"/ini.php?key=memory_limit",
http.StatusOK,
"memory_limit:10000000",
)
}
}
2 changes: 1 addition & 1 deletion phpmainthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func go_frankenphp_main_thread_is_ready() {
// override php.ini directives with those set in the Caddy config
// this needs to happen on each thread and before script execution
func (mainThread *phpMainThread) overridePHPIni() {
if meinThread.phpIniOverrides == nil {
if mainThread.phpIniOverrides == nil {
return
}
for k, v := range mainThread.phpIniOverrides {
Expand Down
7 changes: 7 additions & 0 deletions testdata/ini.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

require_once __DIR__.'/_executor.php';

return function () {
echo $_GET['key'] . ':' . ini_get($_GET['key']);
};

0 comments on commit 6758903

Please sign in to comment.