frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

error 500 with empty response

Open abda11ah opened this issue 9 months ago • 15 comments

What happened?

Hi, I'm using the latest docker image of frankenphp.

I just tried to add a second virtual server at localhost:8080 that will uses the same document-root as the main server.

Now it returns 0 length response + 500 error code :

Here is my caddyfile :

{
    # Global options
    log {
        output file /var/log/caddy/access.log {
            roll_size 10mb
            roll_keep 5
            roll_keep_for 720h
        }
        level error
        format console
    }
    auto_https off
    auto_https disable_redirects

}

localhost:8080 {
    root * /app/html/public
    php_server {
        max_execution_time 0
    }
}

{$SERVER_NAME} {
    handle /presence* {
        reverse_proxy localhost:8080 {
            transport http {
                tls_insecure_skip_verify
            }
        }
    }

    tls {
        protocols tls1.3
    }

    # General handling for other requests
    handle {
        try_files {path} {path}/ /index.php
    }

    
    root * /app/html/public
	php_server
    encode zstd br gzip
    file_server

    @static {
        file extension .js .css .png .jpg .jpeg .gif .ico .svg
    }

    handle @static {
        header Cache-Control "max-age=31536000"
    }

    # Error handling
    handle_errors {
        @404 {
            expression {http.error.status_code} == 404
        }
        rewrite @404 /404
        file_server
    }

    {$CADDY_SERVER_EXTRA_DIRECTIVES}
}

# HTTP to HTTPS redirect
:80 {
    redir https://{host}{uri} permanent
}

I think Caddy should at least return an error message

Image

Build Type

Docker (Debian Bookworm)

Worker Mode

No

Operating System

GNU/Linux

CPU Architecture

x86_64

PHP configuration

Frankenphp latest

Relevant log output


abda11ah avatar Mar 08 '25 12:03 abda11ah

I've just found out what was causing the 500 errors with empty response.

I was missing this line in the global configuration (in the global block at the top) :

frankenphp run --https

Also max_execution_time doesn't exist in caddy nor frankenphp, it's a php.ini directive. But that's not what was causing the 500 error.

abda11ah avatar Mar 08 '25 16:03 abda11ah

Yeah it currently doesn't warn/fail on wrong configuration, there's a PR in the works for that #1424. The upcoming FrankenPHP version will support configuring the php.ini from the Caddyfile, you'll be able to do something like this:

frankenphp {
    php_ini max_execution_time 30
}

AlliBalliBaba avatar Mar 09 '25 10:03 AlliBalliBaba

I got the same issue with dd() from a controller

Image

Image

FACHINA avatar May 30 '25 16:05 FACHINA

@FACHINA does that only happen with dd()? What FrankenPHP version ate you on and are you using worker mode?

AlliBalliBaba avatar May 31 '25 11:05 AlliBalliBaba

@AlliBalliBaba I have noticed this issue arises only when I use the dd() function. It appears that the error page is displayed in the console when I review the Docker logs. But i don't know why it doesn't appear in the navigator,

FACHINA avatar Jun 06 '25 21:06 FACHINA

I think the dd() issue with Symfony might have been fixed by #1592. Do you see the same behaviour in the newest FrankenPHP version? (1.7)

AlliBalliBaba avatar Jun 06 '25 21:06 AlliBalliBaba

@AlliBalliBaba I'm using frankenphp 1.6.2

From dockerfile i got this:

FROM dunglas/frankenphp:1-php8.3 AS frankenphp_upstream

Should i use 1.7.0 instead of 1

FACHINA avatar Jun 07 '25 06:06 FACHINA

I have just pulled the latest version as I noticed it was updated recently, but the issues still persist.

FACHINA avatar Jun 07 '25 07:06 FACHINA

Are you setting your own Content-Length header? I’ve noticed something like this when using var_dump() and setting my own Content-Length headers. The Content-Length and actual content length do not match, and Caddy then refuses to output the body and returns a 500.

withinboredom avatar Jun 07 '25 07:06 withinboredom

I just call the dd() function, no content lenght header was set.

For more info i'm using the https://github.com/dunglas/symfony-docker docker configuration

FACHINA avatar Jun 07 '25 07:06 FACHINA

Someone with more Symfony knowledge than me might have to chime in. It could be some middleware you've set or something as well. If this is the case, Caddy does output an INFO message, IIRC.

withinboredom avatar Jun 07 '25 09:06 withinboredom

Can you check the value of the PHP_SAPI constant right before the dd()? If it's set to cli, that might be the issue.

dd() will also probably log to stdout if it happens during worker setup instead of during a requests.

AlliBalliBaba avatar Jun 07 '25 12:06 AlliBalliBaba

@withinboredom

#[Route(name: 'index', methods: ['GET'])]
    public function index(
        Request $request,
        ArticleRepository $articleRepository,
        PaginatorService $paginator,
        ExportHandler $exportHandler
    ): Response {
        $searchForm = $this->createForm(SearchArticleType::class);
        $searchForm->handleRequest($request);

        if ($exportHandler->intendToExportFromRequest()) {
            $data = $articleRepository->findBySearchQuery($searchForm);
            $exportSchema =  (new ArticleExportSchema($data))
                ->setTitle('Articles')
                ->setDescription('Liste des articles')
                ->setQrCodeData('https://www.google.com');
            return $exportHandler->export($exportSchema);
        }

        return new Response(PHP_SAPI);

}

Image

FACHINA avatar Jun 07 '25 13:06 FACHINA

Hmm this could be also due to xdebug being installed in that image, wasn't able to reproduce it yet. Do you see the same thing happening without xdebug installed?

AlliBalliBaba avatar Jun 09 '25 11:06 AlliBalliBaba

I've faced with the same issue. This issue has helped me a lot https://github.com/symfony/symfony/issues/61340. I've managed to fix this with disabling worker mode from frankenphp. I've used default Caddy configuration:

{
	skip_install_trust

	{$CADDY_GLOBAL_OPTIONS}

	frankenphp {
		{$FRANKENPHP_CONFIG}

		worker {
			file ./public/index.php
			env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
			{$FRANKENPHP_WORKER_CONFIG}
		}
	}
}

I've just removed worker section. So, probably you're running frankenphp in worker mode. You just need to disable it to debug it. Of course disable worker mode for development. On production I would enable it

rfcdt avatar Oct 28 '25 14:10 rfcdt