• We have a continuously reported error in our setup about a missing file in the cache folder even after clearing the cache

    file_get_contents(/home/website_user/public_html/wp-content/cache/autoptimize/js/autoptimize_d41d8cd98f00b204e9800998ecf8427e.js): failed to open stream: No such file or directory

    what does this mean exactly? the files i see there are named autoptimize_single_xxxxxxx.js but the file mentioned is indeed missing

    thanks

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    this happens on a small minority of hosts, can you add this code snippet which forces AO to do some extra checks before writing to cache;

    
    add_filter('autoptimize_filter_cache_checkdirs_on_write','__return_true');

    frank

    Thread Starter carlcs

    (@carlcs)

    Unfortunately, this didn’t work. we disabled autoptimize for now

    thank you

    • This reply was modified 5 years, 1 month ago by carlcs.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    weird, can you copy/paste the full error from your php-errorlog, specifically with the file and line-number where the error got triggered?

    and did this also impact using the site, was it broken?

    Thread Starter carlcs

    (@carlcs)

    hi. the site was not broken and i don’t think there was any impact but it kept appearing in new relic and was filling up the error log there. so i disabled it first to prevent new relic from getting full and step reporting other errors

    Stack trace
    E_WARNING: file_get_contents(/home/web_user/public_html/wp-content/cache/autoptimize/js/autoptimize_d41d8cd98f00b204e9800998ecf8427e.js): failed to open stream: No such file or directory
    in file_get_contents called at /home/web_user/public_html/wp-content/plugins/autoptimize/classes/autoptimizeCache.php (77)
    in autoptimizeCache::retrieve called at /home/web_user/public_html/wp-content/plugins/autoptimize/classes/autoptimizeScripts.php (343)
    in autoptimizeScripts::minify called at /home/web_user/public_html/wp-content/plugins/autoptimize/classes/autoptimizeMain.php (466)
    in autoptimizeMain::end_buffering called at ? (?)
    in ob_end_flush called at /home/web_user/public_html/wp-includes/functions.php (4344)
    in wp_ob_end_flush_all called at /home/web_user/public_html/wp-includes/class-wp-hook.php (286)
    in WP_Hook::apply_filters called at /home/web_user/public_html/wp-includes/class-wp-hook.php (310)
    in WP_Hook::do_action called at /home/web_user/public_html/wp-includes/plugin.php (465)
    in do_action called at /home/web_user/public_html/wp-includes/load.php (954)
    in shutdown_action_hook called at ? (?)
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Very bizarre; as per the code in autoptimizeScripts.php (the 2nd in the stack trace), AO first checks if the cached file exists and only if so retrieves it;

            $this->md5hash = md5( $this->jscode );
            $ccheck = new autoptimizeCache($this->md5hash, 'js');
            if ( $ccheck->check() ) {
                $this->jscode = $ccheck->retrieve();
                return true;
            }

    Moreover autoptimizeCache.php’s retrieve() itself first checks for the file existence (using file_exists) before trying to have file_get_contents it as per the code (full code here, simplified version follows);

        public function retrieve()
        {
            if ( $this->check() ) {
                return file_get_contents( $this->cachedir . $this->filename );
            }
            return false;
        }
        public function check()
        {
            return file_exists( $this->cachedir . $this->filename );
        }

    How it is possible for file_exists to return true but immediately after that for file_get_contents on the same file to return an “failed to open stream: No such file or directory”-error is a complete mystery to me .. :-/

    Thread Starter carlcs

    (@carlcs)

    i reactivated it again and so far, it has not come up. very strange. we’ll observe for the next 24 hours and see if it comes up again.

    Thread Starter carlcs

    (@carlcs)

    it came up again very soon after unfortunately. i disabled it for now

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    no idea why core PHP file_exists would see a file which file_get_contents does not see I’m afraid carlcs, esp. as despite those warnings your site does function correctly for visitors. the only workaround I can think of at this moment if to prepend file_get_contents with an @ to suppress error logging?

    Thread Starter carlcs

    (@carlcs)

    would it matter what our setup is? our setup is in AWS with a load balancer at the front to direct traffic to different web application server clones to handle the load. the cache folder was setup as a shared folder using EFS so that the different clones cache share the same cache. the clones also contain the same filter code you mentioned above.

    thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    EFS/ NFS does matter and although information is sparse I did find one very similar issue in Fast Velocity Minify’s support forum. Could be a case of PHP’s file status cache being updated before the file is readable (so some kind of race condition).

    What we could try is add some additional logic to the retrieve() function to go into a loop until is_readable() returns true or until we think we have tried enough, something like this;

    
        public function retrieve()
        {
            if ( $this->check() ) {
                if ( false == $this->nogzip ) {
                    return file_get_contents( $this->cachedir . $this->filename . '.none' );
                } else {
                    $_iteration = 0;
                    while ( ! is_readable( $this->cachedir . $this->filename ) && $_iteration < 5 ) {
                        usleep( 100000 ); // 1/10th of a second
                        $_iteration++;
                    }
                    return file_get_contents( $this->cachedir . $this->filename );
                }
            }
            return false;
        }
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    hey @carlcs did you find time to try that code out? did it help? ??

    Thread Starter carlcs

    (@carlcs)

    hi. i missed this one but we were dealing with some other issues we encountered so i haven’t had the chance to try it out. will this involve changing the code of autooptimize itself? meaning this snippet won’t be added in to the functions.php file for example but into autooptimize’s code itself?

    thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    no, above code would have to be in autopitimize itself, replacing part of autoptimize/classes/autoptimizeCache.php (see the retrieve() function in there).

    Thread Starter carlcs

    (@carlcs)

    Hi

    sorry for the very late reply. I only had time now to try it out. unfortunately, i’m still getting the same error

    file_get_contents(/home/web_user/public_html/wp-content/cache/autoptimize/js/autoptimize_d41d8cd98f00b204e9800998ecf8427e.js): failed to open stream: No such file or directory

    he full trace is

    E_WARNING: file_get_contents(/home/web_user/public_html/wp-content/cache/autoptimize/js/autoptimize_d41d8cd98f00b204e9800998ecf8427e.js): failed to open stream: No such file or directory
    in file_get_contents called at /home/web_user/public_html/wp-content/plugins/autoptimize/classes/autoptimizeCache.php (97)
    in autoptimizeCache::retrieve called at /home/web_user/public_html/wp-content/plugins/autoptimize/classes/autoptimizeScripts.php (343)
    in autoptimizeScripts::minify called at /home/web_user/public_html/wp-content/plugins/autoptimize/classes/autoptimizeMain.php (466)
    in autoptimizeMain::end_buffering called at ? (?)
    in ob_end_flush called at /home/web_user/public_html/wp-includes/functions.php (4469)
    in wp_ob_end_flush_all called at /home/web_user/public_html/wp-includes/class-wp-hook.php (288)
    in WP_Hook::apply_filters called at /home/web_user/public_html/wp-includes/class-wp-hook.php (312)
    in WP_Hook::do_action called at /home/web_user/public_html/wp-includes/plugin.php (478)
    in do_action called at /home/web_user/public_html/wp-includes/load.php (947)
    in shutdown_action_hook called at ? (?)

    i did notice it’s always the same file that’s reported not found

    thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    weird … could it be that you have some security feature (anti-virus) that is blocking read access to that file even though it’s there, because it is considered unsafe or something like that?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Continously reported missing file in cache even if cache is cleared’ is closed to new replies.