WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
wp-content/cache/tmp filling up with files (9 posts)

  1. agent86ix
    Member
    Posted 1 year ago #

    I'm running w3tc version 0.9.2.11 on a WordPress install, and my host NearlyFreeSpeech. Most things are running fine, but I've noticed that my wp-content/cache/tmp folder is filling up with files that don't seem to be getting removed.

    Right now the only features that are active are the page cache, the DB cache, the browser cache, and I've got a CDN.

    I read a couple of other forum threads that noted similar behavior in version 0.9.2.7, but I've confirmed that I'm up to date and that the issue is still present.

    My host is a bit unusual in the level of security they have on every site's files and directories. Thus, there might be something somewhat unique about my situation that will require some additional debug.

    How do I go about debugging this issue? Where are these files written? Is there a log file or something similar I should be checking for errors?

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. agent86ix
    Member
    Posted 1 year ago #

    A few bits of clarification:

    These files aren't in the WordPress tmp directory, they're in the w3tc tmp directory (wp-content/cache/tmp).

    The files appear to be 0-bytes in length.

    The file names are prefixed with "temp" and then a random string of 6 characters.

    I checked the Apache error logs and there's nothing unusual/related there.

    I wrote a quick PHP script to see if the web server was capable of chmod'ing and unlink'ing these files, and it seems to be able to.

    One thing that's odd about the host is that they require the script that runs to have the same group as the file that it is writing. I don't know what PHP scripts are creating these files (admin? page loads?) but if they're being created by one and unlinked by another, that could be a problem in this environment.

  3. agent86ix
    Member
    Posted 1 year ago #

    I've traced this back a bit, so I'll share my current understanding:

    The temporary files are created in w3-total-cache/inc/functions/file.php, in a function called w3_file_put_contents_atomic. Specifically in my instance, the call to "fopen($temp, 'wb')" appears to be failing.

    This is being called from w3-total-cache/lib/W3/ConfigData.php, in the function write($filename).

    This function is being called from w3-total-cache/lib/W3/ConfigWriter.php in the function create_compiled_config. Here the exception from w3_file_put_contents_atomic is caught, but ignored. If I check this exception, I can see that the fopen call is failing.

    Specifically, my issue appears to be two pronged:

    One is that since safe mode is on, the calling script must have specific permissions to write to the tmp directory. I can adjust the permissions somewhat, but that brings me to the second issue...

    This config file appears to be rewritten on every admin page load. (Thus, when it was failing, it was causing new files to be written very, very often). I don't know if there's anything specific in this config file that requires a refresh every time an admin page loads, but that behavior might be worth investigating.

  4. agent86ix
    Member
    Posted 1 year ago #

    It appears that practically every page load is causing this file to be re-written. For instance, the wp-login.php page calls create_compiled_config via this stacktrace:

    /wp-content/plugins/w3-total-cache/lib/W3/Config.php:118
    /wp-content/plugins/w3-total-cache/lib/W3/Config.php:40
    /wp-content/plugins/w3-total-cache/inc/define.php:1418
    /wp-content/plugins/w3-total-cache/lib/W3/Redirect.php:19
    /wp-content/plugins/w3-total-cache/inc/define.php:1418
    /wp-content/advanced-cache.php:29
    /wp-settings.php:58
    /wp-config.php:103
    /wp-load.php:29
    /wp-login.php:12

    I don't particularly want to open permissions for every php file so that they can all rewrite the w3tc config file. I would just ignore it, but the side effects are bad. Under my host's config, the file gets created, but then it can't be written or unlinked afterwards, so it lingers...

    On top of that, for a plugin that is performance oriented, rewriting the (compiled) config file on every load seems like a bad idea.

  5. agent86ix
    Member
    Posted 1 year ago #

    As best I can figure out, tempnam and safe mode don't work well together:

    https://bugs.php.net/bug.php?id=27133

    This is a 9 year old bug report, but it was marked "not a bug" with the response "Yes, don't use safe-mode or don't use tempnam."

  6. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    Does the server user have write permissions to wp-content/cache/, wp-content/cache/config,wp-content/w3tc-config ?

    The tmp files etc are only generated when trying to create the cached version of the config file. It seems it cannot write/remove/rename the files. If you send a support request from the plugin we can send updated version that does not use the tmp file handling to try out.

  7. agent86ix
    Member
    Posted 1 year ago #

    Frederick,

    Thanks for the response.

    This host is running PHP in safe mode with GID restrictions in effect. Thus, the PHP file requesting access and the file being written have to be owned by the same group.

    All the wp-admin files have the correct group to write (or overwrite) files to those three directories.

    However, it seems as though the function load() in w3-total-cache/lib/W3/Config.php tries to recreate the compiled config file for every page load where an administrator is logged in. It will also attempt to rewrite this file for every visitor if the check for the compiled config fails, regardless of what script is running.

    Since not all scripts have the correct GIDs/permissions to write files under this safe mode restriction, there are lots of attempts to rewrite this file.

    This is compounded by the fact that tempnam() doesn't work properly in safe mode either, so instead of it failing gracefully, the temporary files pile up.

    I'll submit a support request via the plugin if you've got something that you'd like me to test.

  8. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for your input. Will need to look into improving this area. Its not a case we have run into so far. Currently we have only removed the use of tmpfile function. We have plans to add limited file writes with FTP write support for the generation of these files. It will be generated only on config saves for those that require it and support S/FTP saving procedure and by doing that limit need for file write permissions for scripts.

  9. webshopalex
    Member
    Posted 2 months ago #

    So, the following problem i have since one week. When i activate W3 Cache, my server (1and1) is filling up my files (300.000) in 3 hours. In the Cache Folders there are some files but never this amount. When i deactivate the "files" disapear in a short time. In the past year i installed many times the Pluging but never had this prob. A few emails to support are till now not answered. So... where is the problem?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic