error 500 with empty response
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
Build Type
Docker (Debian Bookworm)
Worker Mode
No
Operating System
GNU/Linux
CPU Architecture
x86_64
PHP configuration
Frankenphp latest
Relevant log output
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.
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
}
I got the same issue with dd() from a controller
@FACHINA does that only happen with dd()? What FrankenPHP version ate you on and are you using worker mode?
@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,
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 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
I have just pulled the latest version as I noticed it was updated recently, but the issues still persist.
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.
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
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.
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.
@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);
}
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?
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