我正在尝试部署一个新的Symfony 3.4.10应用程序。这是我第一次部署Symfony应用程序。它使用内置的php服务器在开发环境中运行良好。
我使用nginx作为webserver和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"
我尝试加载的页面只是一个连接表单。
我在我的php.ini
中分配了1024MB,认为这是因为应用程序在第一次调用时需要更多RAM。
真正奇怪的是,日志告诉内存大小已经耗尽,但应用程序尝试分配的数量非常低:20480 bytes
分配给最大量的1073741824 bytes
,我不明白为什么它失败以及如何解决这个问题。
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;
}
好的,所以我想到了如何使我的应用程序正常工作!这是我的文件的权利问题,php-fpm的用户无法访问文件,这导致Symfony尝试发送错误。
我不知道为什么Symfony LogicException: Missing stream url, the stream can not be opened. This may be caused by a premature call to close().
抛出的异常会超出内存限制,所以如果有人知道原因,那么解释它会非常有帮助!
这是有道理的:
(1073741824b + 20480b)/1024/1024 = 1024mb
额外的20480b将其置于极限。
你总是可以在php.ini中设置,但真正的问题是为什么它消耗了那么多内存? Symfony常常消耗那么多吗?此外,如果存在某种类型的泄漏或无限制的内存消耗过程,它可能会在某些时候因内存量增加而崩溃。