Title: PHP Warnings on cache cleanup
Last modified: September 14, 2022

---

# PHP Warnings on cache cleanup

 *  Resolved [mrsmurf](https://wordpress.org/support/users/mrsmurf/)
 * (@mrsmurf)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-warnings-on-cache-cleanup/)
 * 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](https://wordpress.org/support/users/mrsmurf/)
 * (@mrsmurf)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-warnings-on-cache-cleanup/#post-16008606)
 * 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](https://wordpress.org/support/users/mrsmurf/).
 *  [Harshad](https://wordpress.org/support/users/bornforphp/)
 * (@bornforphp)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-warnings-on-cache-cleanup/#post-16011181)
 * [@mrsmurf](https://wordpress.org/support/users/mrsmurf/) Thanks for sharing this,
   I’ll share the same with our development team.
 *  Plugin Contributor [Venkat Raj](https://wordpress.org/support/users/webulous/)
 * (@webulous)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-warnings-on-cache-cleanup/#post-16022641)
 * [@mrsmurf](https://wordpress.org/support/users/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/](https://developer.wordpress.org/reference/functions/wp_mkdir_p/)
 *  Plugin Author [David Anderson / Team Updraft](https://wordpress.org/support/users/davidanderson/)
 * (@davidanderson)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-warnings-on-cache-cleanup/#post-16023520)
 * 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.

 * ![](https://ps.w.org/wp-optimize/assets/icon-256x256.png?rev=1552899)
 * [WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance](https://wordpress.org/plugins/wp-optimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-optimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-optimize/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-optimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-optimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-optimize/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [David Anderson / Team Updraft](https://wordpress.org/support/users/davidanderson/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/php-warnings-on-cache-cleanup/#post-16023520)
 * Status: resolved