简体   繁体   English

Symfony 5.3 中的 MIME header 错误

[英]Malformed MIME header error in Symfony 5.3

I'm working on a project with Symfony 5.3 with PHP 8.0.12.我正在使用 Symfony 5.3 和 PHP 8.0.12 开展项目。 I've been developing it on my own computer, it's working well.我一直在自己的电脑上开发它,它运行良好。 I now want to deploy it on a remote container.我现在想将它部署在远程容器上。

However when I start the Symfony built in Webserver I'm getting the following error when accessing any of the defined routes:但是,当我启动内置于 Webserver 的 Symfony 时,访问任何已定义的路由时都会出现以下错误:

issue with server callback error="unable to fetch the response from the backend: malformed MIME header: missing colon: "FROM information_schema.schemata""

In both cases (on my computer and in the container), the server is connecting to a remote PostgreSQL database.在这两种情况下(在我的计算机和容器中),服务器都连接到远程 PostgreSQL 数据库。 The container doesn't seem to have any problem connecting to the database though, as I can manually connect using the psql command.容器连接到数据库似乎没有任何问题,因为我可以使用 psql 命令手动连接。

I've tried reinstalling Symfony (Symfony CLI version v4.26.8), Composer (version 2.1.12), and most PHP libraries but that didn't change anything.我尝试重新安装 Symfony(Symfony CLI 版本 v4.26.8)、Composer(版本 2.1.12)和大多数 PHP 库,但这并没有改变任何东西。

I have no idea where the problem is.我不知道问题出在哪里。 Any help would be greatly appreciated.任何帮助将不胜感激。

Here is my composer.json:这是我的作曲家.json:

{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
    "php": ">=7.2.5",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "ext-json": "*",
    "composer/package-versions-deprecated": "1.11.99.2",
    "doctrine/annotations": "^1.13",
    "doctrine/doctrine-bundle": "^2.4",
    "doctrine/doctrine-migrations-bundle": "^3.1",
    "doctrine/orm": "^2.9",
    "lexik/jwt-authentication-bundle": "^2.13",
    "sensio/framework-extra-bundle": "^6.2",
    "symfony/apache-pack": "^1.0",
    "symfony/dotenv": "5.3.*",
    "symfony/flex": "^1.15",
    "symfony/framework-bundle": "5.3.*",
    "symfony/http-foundation": "5.3.*",
    "symfony/ldap": "5.3.*",
    "symfony/proxy-manager-bridge": "5.3.*",
    "symfony/security-bundle": "5.3.*",
    "symfony/stopwatch": "5.3.*",
    "symfony/web-profiler-bundle": "5.3.*",
    "symfony/property-access": "5.3.*",
    "symfony/runtime": "5.3.*",
    "symfony/security-csrf": "5.3.*",
    "symfony/serializer": "5.3.*",
    "symfony/yaml": "5.3.*"
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": {
        "*": "dist"
    },
    "sort-packages": true
},
"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Tests\\": "tests/"
    }
},
"replace": {
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php72": "*"
},
"scripts": {
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
        "@auto-scripts"
    ],
    "post-update-cmd": [
        "@auto-scripts"
    ]
},
"conflict": {
    "symfony/symfony": "*"
},
"extra": {
    "symfony": {
        "allow-contrib": false,
        "require": "5.3.*"
    }
},
"require-dev": {
    "symfony/maker-bundle": "^1.33"
}
}

I have had this error when using symfony server:start with docker inside a php-alpine container.使用symfony server:start php-alpine 容器中的 docker 开始。 Each time i run migrations or doctrine:schema:update in a fresh installed instance, my symfony local web-server would throw error: issue with server callback error="unable to fetch the response from the backend: malformed MIME header: missing colon: "FROM information_schema.schemata I solved it by dropping the alpine container and building everything from the FROM ubuntu:20.04 image: i had to install php, drivers and all dependencies too.每次我在新安装的实例中运行迁移或 doctrine:schema:update 时,我的 symfony 本地网络服务器都会抛出错误: issue with server callback error="unable to fetch the response from the backend: malformed MIME header: missing colon: "FROM information_schema.schemata我通过删除 alpine 容器并从FROM ubuntu:20.04图像构建所有内容来解决它:我必须安装 php、驱动程序和所有依赖项。 This did not go well with my production env because the image was above 1GB, meaning it had binaries i did not need in production.这与我的生产环境不兼容,因为图像高于 1GB,这意味着它具有我在生产中不需要的二进制文件。 From experience the symfony local web-server needs a python environment but am not sure on that.根据经验,symfony 本地 Web 服务器需要 python 环境,但我不确定。

After some days, i stumbled on this git repository: https://github.com/dunglas/symfony-docker .几天后,我偶然发现了这个 git 存储库: https://github.com/dunglas/symfony-docker which is recommended from symphony docs here: Using Docker with Symfony .这是从这里的交响乐文档中推荐的: Using Docker with Symfony It uses caddy as the web-server.它使用 caddy 作为网络服务器。 I learnt from it, tweaked to suit my needs and from then never used symfony local web-server.我从中吸取了教训,根据我的需要进行了调整,从那时起我就再也没有使用过 symfony 本地网络服务器。 Its a good project, kudos to Kévin Dunglas and maintainers.这是一个很好的项目,感谢 Kévin Dunglas和维护者。 The php image is about 200MB. php 映像约为 200MB。 Caddy too is about 40MB. Caddy 也是大约 40MB。 Great for both prod and dev environments.非常适合产品和开发环境。

Please peruse the repo and adopt what you can or everything.请仔细阅读 repo 并采用你能做的或一切。

Disclaimer: This is not an answer to your problem/error, but an easy alternative.免责声明:这不是您的问题/错误的答案,而是一个简单的替代方案。

I have experienced the same issue running inside docker (ubuntu).我在 docker (ubuntu) 中遇到了同样的问题。 Although I am not entirely sure why this happens I have managed to find a workaround that's easy:虽然我不完全确定为什么会发生这种情况,但我设法找到了一个简单的解决方法:

composer install 
composer run-script auto-scripts
symfony proxy:start --host=0.0.0.0 
symfony local:server:start --no-tls --port=8000

No idea why this works, but when you run it in docker exactly THIS way everything works just fine and you can open your application at CONTAINER_IP:8000 .不知道为什么会这样,但是当你在 docker 中运行它时,一切正常,你可以在CONTAINER_IP:8000打开你的应用程序。

I decided to post this here, since it took me 3 hours to figure it out so hopefully this saves somebody's time.我决定在这里发布这个,因为我花了 3 个小时才弄明白,所以希望这可以节省别人的时间。

My quick solution is to remove new lines from the query in file: vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php method: getListTableMetadataSQL我的快速解决方案是从文件中的查询中删除新行: vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php方法: getListTableMetadataSQL

From

        return sprintf(
            <<<'SQL'
SELECT ENGINE, AUTO_INCREMENT, TABLE_COLLATION, TABLE_COMMENT, CREATE_OPTIONS
FROM information_schema.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s
SQL

to:至:

        return sprintf(
            <<<'SQL'
SELECT ENGINE, AUTO_INCREMENT, TABLE_COLLATION, TABLE_COMMENT, CREATE_OPTIONS FROM information_schema.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s
SQL

Of course, it comes back after composer install, but this shows source of the problem当然,它在 composer install 之后又回来了,但这说明了问题的根源

Before After之前之后

For me - it was a permission issue of the "var" directory.对我来说 - 这是“var”目录的权限问题。 Also in Docker.同样在 Docker 中。

NOTICE: PHP message: PHP Fatal error:  Uncaught RuntimeException: Unable to create the "logs" directory (/app/var/log). in /app/vendor/symfony/http-kernel/Kernel.php:626

Making the directory writable resolved the issue.使目录可写解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM