简体   繁体   中英

Symfony HTTP 500 error after several requests in production

I'm using Symfony v3.0.9. Everything works fine locally, but when I move the application to production, after a while, I start receiving errors such as:

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

or

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 

or

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

(both of these files exist and they can be accessed just fine by the web server)

Sometimes the app works fine after clearing the cache and/or composer install sometimes it doesn't and it takes several tries after it finally works again. No changes in the source code.

I'm thinking that this could be related to simultaneous requests being processed by the app which could cause some anomalies in the cached files.

Any ideas?

Update #1 - vhost config:

<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>

Update #2 - memory_limit update:

I updated memory_limit in PHP from 256MB to -1 (no limit) and so far I haven't encountered the 500 error, except once. It was due to PHP Fatal error: Cannot access property appProdProjectContainer::$parameters and it got fixed just after the first rm -rf var/cache/prod

Also in vhosts.conf or httpd.conf verify you have access granted to your web directory:

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

I have something similar some time ago on Mac OS. Apache or PHP start crashing for now reason with the messages like you've shown

On Mac there was a problem with a limit on the number of open files. You can get some info here https://superuser.com/questions/433746/is-there-a-fix-for-the-too-many-open-files-in-system-error-on-os-x-10-7-1 .

I ended up running the following commands to fix it

sudo launchctl limit maxfiles 10000000 10000000
sudo apachectl restart

I had to face kind of similar issue not so long ago - sometimes some files (mostly templates and/or routing files) were not found, yet they were on the server. I found out that it was because I was uploading them to the server via Filezilla using my own username/password (so my user on the server was the owner of these files), but the symfony app was running under another user and this user could not use files if he was not their owner.

I am not sure you are facing the same problem as me though, but I hope it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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