Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=dump123",
http.StatusInternalServerError,
"dump123",
)
}
14 changes: 9 additions & 5 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,16 @@ 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();
Expand Down
32 changes: 32 additions & 0 deletions testdata/dd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

// simulate Symfony's dd() behavior
// see https://github.com/symfony/http-kernel/blob/7.3/DataCollector/DumpDataCollector.php#L216
class Dumper
{
private string $message;

public function dump(string $message): void
{
http_response_code(500);
$this->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);
})) {
// keep handling requests
}

echo "we should never reach here\n";
Loading