• Resolved mrsmurf

    (@mrsmurf)


    Hi, I have noticed that when multiple visitors trigger a cache cleanup there are lots of PHP warnings complaining about “No such file or directory” when trying to do unlink.

    Since I am very allergic to PHP warnings you should modify /wp-content/plugins/wp-optimize/cache/file-based-page-cache-functions.php on line 1072 to first check if the file exists before trying to remove it.

    Something like:
    if (file_exists($src . ‘/’ . $file) && !unlink($src . ‘/’ . $file)) {
    $success = false;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mrsmurf

    (@mrsmurf)

    In the same way the cache_path function in the WP_Optimize_Minify_Cache_Functions class has a similar reverse race condition where you first check if the directory exists then try to create it, and if someone else beats you to it it will trigger an error.

    if (!is_dir($target) && !wp_mkdir_p($target)) {
    error_log(‘WP_Optimize_Minify_Cache_Functions::cache_path(): The folder “‘.$target.'” could not be created.’);
    }

    Could perhaps be:

    if (!is_dir($target) && !wp_mkdir_p($target)) {
    if(!is_dir($target))
    error_log(‘WP_Optimize_Minify_Cache_Functions::cache_path(): The folder “‘.$target.'” could not be created.’);
    }

    • This reply was modified 3 years, 7 months ago by mrsmurf.

    @mrsmurf Thanks for sharing this, I’ll share the same with our development team.

    Plugin Contributor Venkat Raj

    (@webulous)

    @mrsmurf We are applying your first suggestion in our next release.

    However, I don’t think the second one has a race condition.

    If some other process/user created the director wp_mkdir_p will return true if the directory already exists.
    https://developer.wordpress.org/reference/functions/wp_mkdir_p/

    Plugin Author David Anderson / Team Updraft

    (@davidanderson)

    N.B. Your suggested code still has a race condition. file_exists() and unlink() run consecutively, and in the mean-while another process might have removed the file – so there’s the same window in between those two as there is currently between readdir() and unlink().

    (I have proposed to our developer a superior method that will do what is intended, and that will be implemented instead).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘PHP Warnings on cache cleanup’ is closed to new replies.