From 139c666fa294cd76d55764d89e671f04b8d2b257 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Mon, 27 Oct 2025 23:15:32 +0100 Subject: [PATCH 1/6] Verifies exit behavior. --- caddy/caddy_test.go | 24 ++++++++++++++++++++++++ frankenphp.c | 13 ++++++++----- testdata/dd.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 testdata/dd.php diff --git a/caddy/caddy_test.go b/caddy/caddy_test.go index efd9e30aa9..a235dbbc1f 100644 --- a/caddy/caddy_test.go +++ b/caddy/caddy_test.go @@ -1423,3 +1423,27 @@ func TestWorkerMatchDirectiveWithoutFileServer(t *testing.T) { // the request should completely fall through the php_server module tester.AssertGetResponse("http://localhost:"+testPort+"/static.txt", http.StatusNotFound, "Request falls through") } + +func TestDd(t *testing.T) { + tester := caddytest.NewTester(t) + tester.InitServer(` + { + skip_install_trust + admin localhost:2999 + } + + http://localhost:`+testPort+` { + php { + worker ../testdata/dd.php 1 { + match * + } + } + `, "caddyfile") + + // simulate Symfony's dd() + tester.AssertGetResponse( + "http://localhost:"+testPort+"/some-path?output=", + http.StatusServerError, + "dd output" + ) +} diff --git a/frankenphp.c b/frankenphp.c index 69e29ed9dd..cc9585a070 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -464,12 +464,15 @@ PHP_FUNCTION(frankenphp_handle_request) { /* * If an exception occurred, print the message to the client before - * closing the connection and bailout. + * closing the connection. */ - if (EG(exception) && !zend_is_unwind_exit(EG(exception)) && - !zend_is_graceful_exit(EG(exception))) { - zend_exception_error(EG(exception), E_ERROR); - zend_bailout(); + if (EG(exception)) { + if(!zend_is_unwind_exit(EG(exception)) && !zend_is_graceful_exit(EG(exception))){ + zend_exception_error(EG(exception), E_ERROR); + } else { + /* exit() will jump directly to after php_execute_script */ + zend_bailout(); + } } frankenphp_worker_request_shutdown(); diff --git a/testdata/dd.php b/testdata/dd.php new file mode 100644 index 0000000000..a6cfd73ece --- /dev/null +++ b/testdata/dd.php @@ -0,0 +1,29 @@ +message = $message; + } + + public function __destruct() + { + if (isset($this->message)) { + echo $this->message; + } + } +} + +$dumper = new Dumper(); + +while (frankenphp_handle_request(function () use ($dumper) { + $dumper->dump($_GET['output']); + exit(1); +})) { + // noop +} \ No newline at end of file From f3233d59aa2bd14ad119aa3e813a2495eac0cd0b Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Mon, 27 Oct 2025 23:17:28 +0100 Subject: [PATCH 2/6] formatting --- frankenphp.c | 3 ++- testdata/dd.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frankenphp.c b/frankenphp.c index cc9585a070..3d124eced1 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -467,7 +467,8 @@ PHP_FUNCTION(frankenphp_handle_request) { * closing the connection. */ if (EG(exception)) { - if(!zend_is_unwind_exit(EG(exception)) && !zend_is_graceful_exit(EG(exception))){ + if (!zend_is_unwind_exit(EG(exception)) && + !zend_is_graceful_exit(EG(exception))) { zend_exception_error(EG(exception), E_ERROR); } else { /* exit() will jump directly to after php_execute_script */ diff --git a/testdata/dd.php b/testdata/dd.php index a6cfd73ece..6a62060020 100644 --- a/testdata/dd.php +++ b/testdata/dd.php @@ -1,6 +1,7 @@ dump($_GET['output']); exit(1); })) { - // noop + // keep handling requests } \ No newline at end of file From 56f3d6b421b1327f66791248b06e44293f9b7751 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Mon, 27 Oct 2025 23:29:33 +0100 Subject: [PATCH 3/6] Checks for actual exit. --- testdata/dd.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testdata/dd.php b/testdata/dd.php index 6a62060020..903d14ae40 100644 --- a/testdata/dd.php +++ b/testdata/dd.php @@ -23,8 +23,10 @@ public function __destruct() $dumper = new Dumper(); while (frankenphp_handle_request(function () use ($dumper) { - $dumper->dump($_GET['output']); + $dumper->dump($_GET['output'] ?? ''); exit(1); })) { // keep handling requests -} \ No newline at end of file +} + +echo "we should never reach here\n"; \ No newline at end of file From 36dbd009fc39b589b8574b894ef2a6560d17a361 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Tue, 28 Oct 2025 00:03:42 +0100 Subject: [PATCH 4/6] Fixes test. --- caddy/caddy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caddy/caddy_test.go b/caddy/caddy_test.go index a235dbbc1f..a9b595fe2a 100644 --- a/caddy/caddy_test.go +++ b/caddy/caddy_test.go @@ -1444,6 +1444,6 @@ func TestDd(t *testing.T) { tester.AssertGetResponse( "http://localhost:"+testPort+"/some-path?output=", http.StatusServerError, - "dd output" + "dd output", ) } From ab4f1629982eb77835c0e141d25fa586ef503a82 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Tue, 28 Oct 2025 00:06:30 +0100 Subject: [PATCH 5/6] Fixes test. --- caddy/caddy_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/caddy/caddy_test.go b/caddy/caddy_test.go index a9b595fe2a..917385683b 100644 --- a/caddy/caddy_test.go +++ b/caddy/caddy_test.go @@ -1442,8 +1442,8 @@ func TestDd(t *testing.T) { // simulate Symfony's dd() tester.AssertGetResponse( - "http://localhost:"+testPort+"/some-path?output=", - http.StatusServerError, - "dd output", + "http://localhost:"+testPort+"/some-path?output=dump123", + http.StatusInternalServerError, + "dump123", ) } From 31141e5ba19f27e226814d5430ae9fb9745dfd2c Mon Sep 17 00:00:00 2001 From: Alexander Stecher <45872305+AlliBalliBaba@users.noreply.github.com> Date: Tue, 28 Oct 2025 09:01:22 +0100 Subject: [PATCH 6/6] Update testdata/dd.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kévin Dunglas --- testdata/dd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdata/dd.php b/testdata/dd.php index 903d14ae40..14bafc3e63 100644 --- a/testdata/dd.php +++ b/testdata/dd.php @@ -29,4 +29,4 @@ public function __destruct() // keep handling requests } -echo "we should never reach here\n"; \ No newline at end of file +echo "we should never reach here\n";