简体   繁体   中英

Symfony 3 cache build up with ezplatform

I have a few sites running on symfony 3 with ezplatform but the cache folder just grows indefinitely and requires that I manually clear it once a week.

root@myserver:/# df -ih
Filesystem        Inodes IUsed IFree IUse% Mounted on
/dev/ploop41633p1   6,2M  2,5M  3,7M   41% /
none                256K    17  256K    1% /sys/fs/cgroup
none                256K    79  256K    1% /dev
tmpfs               256K     1  256K    1% /dev/shm
tmpfs               256K   180  256K    1% /run
tmpfs               256K     3  256K    1% /run/lock
none                256K     1  256K    1% /run/shm

The free nodes increased from 32% free to 41% free over the weekend.

The host is running with 2gig ram and a 100gig SSD.

The system is running on Apache 2.4 without any Varnish cache, and we don't want to have to think about the overhead of a Varnish cache for this site as is overkill.

I just cleared the entire cache of the site and running the same command as above show:

root@acrontum01:/# df -ih
Filesystem        Inodes IUsed IFree IUse% Mounted on
/dev/ploop41633p1   6,2M   85K  6,1M    2% /
none                256K    17  256K    1% /sys/fs/cgroup
none                256K    79  256K    1% /dev
tmpfs               256K     1  256K    1% /dev/shm
tmpfs               256K   180  256K    1% /run
tmpfs               256K     3  256K    1% /run/lock
none                256K     1  256K    1% /run/shm

It cannot be that the only way to keep this server alive is by running a manual cache clear on cron?

The apache vhost file is as follows, with the SYMFONY_ENV set to prod:

<IfModule mod_ssl.c>
<VirtualHost 0.0.0.0:443 >
    ServerName "myserver.com:443"
    ServerAlias "www.myserver.com"
    ServerAlias "myserver.com"

    ServerAdmin "info@myserver.com"

    UseCanonicalName Off

    DocumentRoot "/var/www/vhosts/myserver.com/releases/current/web"

   <Directory /var/www/vhosts/myserver.com/releases/current/web>
        SSLRequireSSL
        Options -Includes -ExecCGI
    </Directory>

    DirectoryIndex "app.php" "index.html" "index.cgi" "index.pl" "index.php" "index.xhtml" "index.htm" "index.shtml"

    <FilesMatch "\.(jpeg|jpg|png|gif|js|css|woff2)$">
        ExpiresActive On
        ExpiresDefault "access plus 1 week"
    </FilesMatch>

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^myserver\.de$ [NC]
        RewriteRule ^(.*)$ https://www.myserver.com$1 [L,R=301]
    </IfModule>

    ## eZ Platform/Symfony ENVIRONMENT variables, used for customizing app.php execution (not used by console commands)

    # Environment.
    # Possible values: "prod" and "dev" out-of-the-box, other values possible with proper configuration
    # Defaults to "prod" if omitted (uses SetEnvIf so value can be used in rewrite rules)
    SetEnvIf Request_URI ".*" SYMFONY_ENV=prod

    # Optional: Whether to use custom ClassLoader (autoloader) file
    # Needs to be a valid path relative to root web/ directory
    # Defaults to bootstrap.php.cache, or autoload.php in debug if env value is omitted or empty
    #SetEnv SYMFONY_CLASSLOADER_FILE ""

    # Optional: Whether to use debugging.
    # Possible values: 0, 1 or ""
    # Defaults to enabled if SYMFONY_ENV is set to "dev" if env value is omitted or empty
    SetEnv SYMFONY_DEBUG 0

    # Optional: Whether to use Symfony's builtin HTTP Caching Proxy.
    # Disable it if you are using an external reverse proxy (e.g. Varnish)
    # Possible values: 0, 1 or ""
    # Defaults to disabled if SYMFONY_ENV is set to "dev" or SYMFONY_TRUSTED_PROXIES is set,
    # and if this env value is omitted or empty
    SetEnv SYMFONY_HTTP_CACHE 1

    # Optional: Whether to use custom HTTP Cache class if SYMFONY_HTTP_CACHE is enabled
    # Value must be a autoloadable cache class
    # Defaults to to use provided "AppCache" if env value is omitted or empty
    #SetEnv SYMFONY_HTTP_CACHE_CLASS ""

    # Optional: Defines the proxies to trust
    # Needed when using Varnish as proxy, if so disable SYMFONY_HTTP_CACHE.
    # Separate entries by a comma, example: "proxy1.example.com,proxy2.example.org"
    # Defaults to not be set if env value is omitted or empty
    #SetEnv SYMFONY_TRUSTED_PROXIES ""

    <IfModule mod_rewrite.c>
        RewriteEngine On

        # For FastCGI mode or when using PHP-FPM, to get basic auth working.
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

        # Needed for ci testing, you can optionally remove this.
        RewriteCond %{ENV:SYMFONY_ENV} "behat"
        RewriteCond %{REQUEST_URI} ^/php5-fcgi(.*)
        RewriteRule . - [L]

        # Cluster/streamed files rewrite rules. Enable on cluster with DFS as a binary data handler
        #RewriteRule ^/var/([^/]+/)?storage/images(-versioned)?/.* /app.php [L]

        RewriteRule ^/var/([^/]+/)?storage/images(-versioned)?/.* - [L]

        # Makes it possible to place your favicon at the root of your eZ Platform instance.
        # It will then be served directly.
        RewriteRule ^/favicon\.ico - [L]

        # Give direct access to robots.txt for use by crawlers (Google, Bing, Spammers...)
        # managed by seo bundle        RewriteRule ^/robots\.txt - [L]

        # Platform for Privacy Preferences Project ( P3P ) related files for Internet Explorer
        # More info here : http://en.wikipedia.org/wiki/P3p
        RewriteRule ^/w3c/p3p\.xml - [L]

        # The following rule is needed to correctly display bundle and project assets
        RewriteRule ^/bundles/ - [L]
        RewriteRule ^/assets/ - [L]

        # Additional Assetic rules for environments different from dev,
        # remember to run php app/console assetic:dump --env=prod
        RewriteCond %{ENV:SYMFONY_ENV} !^(dev)
        RewriteRule ^/(css|js|fonts?)/.*\.(css|js|otf|eot|ttf|svg|woff) - [L]

        RewriteRule .* /app.php
    </IfModule>

    # Everything below is optional to improve performance by forcing
    # clients to cache image and design files, change the expires time
    # to suite project needs.
    <IfModule mod_expires.c>
        <LocationMatch "^/var/[^/]+/storage/images/.*">
            # eZ Platform appends the version number to image URL (ezimage
            # datatype) so when an image is updated, its URL changes too
            ExpiresActive on
            ExpiresDefault "now plus 10 years"
        </LocationMatch>
    </IfModule>


    <Directory /var/www/vhosts/myserver.com/releases/current>
        AllowOverride AuthConfig FileInfo Limit Options=SymLinksIfOwnerMatch,MultiViews,FollowSymLinks,ExecCGI,Includes,IncludesNOEXEC
    </Directory>

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/myserver.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/myserver.com/privkey.pem
</VirtualHost>
</IfModule>

There are two types of filesystem caches in eZ Platform:

1) Persistence cache - caches the content loaded from the database. Size of this cache directly corelates with number of content you have. If you have hundreds of thousands of content objects, this can be the bottleneck.

2) HTTP cache - created by the Symfony reverse proxy (enabled with SetEnv SYMFONY_HTTP_CACHE 1 in your vhost). If you have a lots of logged in users or your anonymous users somehow create a session, or if the caching is misconfigured somehow, this can potentially be the cause, depending on the contents of your Vary response headers sent by the app.

In any case, none of these caches are cleared automatically, unfortunatelly. You will need to clear them by yourself.

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