部署 Symfony 3.4.10 应用程序错误:允许的内存大小被 StreamHandler.php 耗尽

dar*_*ale 2 php nginx out-of-memory web-deployment symfony-3.4

语境

我正在尝试部署一个新的 Symfony 3.4.10 应用程序。这是我第一次部署 Symfony 应用程序。它在使用内置 php 服务器的开发环境中运行良好。

我使用 nginx 作为网络服务器和 php-fpm。

问题

当我尝试访问我的应用程序时,我的日志中会抛出一个错误:

2018/05/25 02:32:03 [error] 15819#15819: *1 FastCGI sent in stderr: 
    "PHP message: PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted 
    (tried to allocate 20480 bytes) 
    in /var/www/my-project/application/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php 
    on line 107
PHP message: PHP Fatal error: 
    Allowed memory size of 1073741824 bytes exhausted 
    (tried to allocate 20480 bytes) 
    in /var/www/my-project/application/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php 
    on line 107"
    while reading response header from upstream, 
    client: xx.xx.xx.xx, server: preprod.my-website.fr, 
    request: "GET / HTTP/2.0", 
    upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", 
    host: "preprod.mywebsite.fr"
Run Code Online (Sandbox Code Playgroud)

我尝试加载的页面只是一个连接表单。

我在我的 中分配了 1024MB php.ini,认为这是因为应用程序在第一次调用时需要更多 RAM。

看起来真正奇怪的是,日志告诉内存大小已耗尽,但应用程序尝试分配的数量非常低:20480 bytes分配了最大数量1073741824 bytes,我不明白为什么它会失败以及如何解决这个问题。

我的网站nginx配置:

server {
    listen 443;
    listen [::]:443;

    server_name preprod.my-website.fr;
    root /var/www/my-project/application/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }

    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/my-project_error.log;
    access_log /var/log/nginx/my-project_access.log;

    # SSL configuration
    ssl on;
    ssl_certificate /etc/letsencrypt/live/preprod.my-website.fr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/preprod.my-website.fr/privkey.pem;
}

server {
    listen 0.0.0.0:80;
    server_name preprod.my-website.fr;
    rewrite ^ https://$host$request_uri? permanent;
}
Run Code Online (Sandbox Code Playgroud)

dar*_*ale 5

好的,我已经弄清楚如何使我的应用程序正常工作了!这是我的文件的权限问题,php-fpm 的用户无法访问这些文件,这导致 Symfony 尝试发送错误。

我不知道为什么 Symfony 抛出的异常会LogicException: Missing stream url, the stream can not be opened. This may be caused by a premature call to close().超出内存限制,所以如果有人知道为什么,解释它会非常有帮助!