【问题标题】:Symfony HTTP 500 error after several requests in productionSymfony HTTP 500 错误在生产中的多个请求后
【发布时间】:2017-05-16 11:12:37
【问题描述】:

我正在使用 Symfony v3.0.9。在本地一切正常,但是当我将应用程序移至生产环境时,过了一会儿,我开始收到如下错误:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Config\Exception\FileLoaderLoadException: "Unable to find file "@FrontendBundle/Resources/config/routing.yml" in @FrontendBundle/Resources/config/routing.yml

request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "Unable to find template "FrontendBundle::homepage/homepage.html.twig" (looked into: [...]/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form)." at [...]/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128 

PHP Fatal error:  Cannot access  property appProdProjectContainer::$parameters in [...]/var/cache/prod/appProdProjectContainer.php on line 30

(这两个文件都存在,并且可以通过网络服务器正常访问)

有时应用程序在清除缓存后可以正常工作和/或composer install 有时不能,并且在最终再次工作后需要多次尝试。源代码没有变化。

我认为这可能与应用正在处理的同时请求有关,这可能会导致缓存文件出现一些异常。

有什么想法吗?

更新 #1 - 虚拟主机配置:

<VirtualHost *:80 *:443>
    ServerName example.net
    ServerAlias www.example.net example.com www.example.com example.org www.example.org
    DocumentRoot /home/example/www/example.net/web/
    ErrorLog  /home/example/www/example.net/logs/error.log
    CustomLog /home/example/www/example.net/logs/access.log combined

    RewriteEngine on

    RewriteCond %{HTTP_HOST} example\.(org|com)$ [NC]
    RewriteRule ^(.*)$ https://www.example.net$1 [R=301,L]

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}$1 [R=301,L]

    AssignUserId example www-data

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/www.example.net/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.example.net/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/www.example.net/chain.pem
</VirtualHost>

更新 #2 - memory_limit 更新:

我将 PHP 中的 memory_limit 从 256MB 更新为 -1(无限制),到目前为止我还没有遇到 500 错误,除了一次。这是由于PHP Fatal error: Cannot access property appProdProjectContainer::$parameters 而在第一个rm -rf var/cache/prod 之后得到修复的

【问题讨论】:

  • 这是一些奇怪的行为。你能详细说明你的虚拟主机配置+文件权限吗?
  • 我不确定 Virtualhost 是否与此相关,无论哪种方式,我都使用 Virtualhost 配置更新了我的问题。此外,文件权限应该没问题:在应用程序工作和不工作之间文件权限没有变化。无论如何,这里是@FrontendBundle/Resources/config/routing.yml 的权限:-rw-rw-r-- 1 example example 2103 Dec 26 23:35 FrontendBundle/Resources/config/routing.yml
  • 好像是cmets @Florent这样的文件权限问题
  • 您是否有区分大小写的问题? (开发上的 mac,产品上的 linux 或类似的东西?)
  • 不,据说丢失的文件存在于文件系统中。这就是为什么我认为这可能只是一个并发问题。

标签: php symfony


【解决方案1】:

同样在 vhosts.confhttpd.conf 中验证您是否有权访问您的 Web 目录:

<Directory "/home/example/www/example.net/web/">
    DirectoryIndex app.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

【讨论】:

  • 是的,肯定是被授予的,否则我根本无法访问该应用程序。此外,权限没有变化。
【解决方案2】:

我前段时间在 Mac OS 上也有类似的东西。 Apache 或 PHP 现在因为您显示的消息而开始崩溃

在 Mac 上存在打开文件数量限制的问题。你可以在这里获得一些信息https://superuser.com/questions/433746/is-there-a-fix-for-the-too-many-open-files-in-system-error-on-os-x-10-7-1

我最终运行了以下命令来修复它

sudo launchctl limit maxfiles 10000000 10000000
sudo apachectl restart

【讨论】:

  • 我监控了打开文件的数量,但似乎并非如此:cat /proc/sys/fs/file-max ==> 3274219。尽管如此,打开的文件数量在 450 左右变化:lsof | wc -l
【解决方案3】:

不久前我不得不面对类似的问题 - 有时找不到某些文件(主要是模板和/或路由文件),但它们在服务器上。我发现这是因为我使用自己的用户名/密码通过 Filezilla 将它们上传到服务器(所以我在服务器上的用户是这些文件的所有者),但是 symfony 应用程序在另一个用户下运行,这个用户可以如果他不是文件的所有者,则不要使用文件。

虽然我不确定您是否面临与我相同的问题,但我希望它会对您有所帮助。

【讨论】:

  • 不幸的是,服务器在与上传这些文件的用户相同的用户下运行,所以情况并非如此。
猜你喜欢
  • 2011-03-18
  • 2015-07-11
  • 1970-01-01
  • 1970-01-01
  • 2021-12-08
  • 2017-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多