Geeklog-Core / geeklog

Geeklog - The Secure CMS.
https://www.geeklog.net
25 stars 19 forks source link

Sporadic Error Deleting Expired Cached Files #1138

Closed eSilverStrike closed 1 year ago

eSilverStrike commented 1 year ago

Since updating to Geeklog 2.2.2 (from current repository) and PHP 8.1 one of my websites every day or so puts an error like this in the error log

Sun Jul 24 01:51:51 2022 - 5.161.131.123 - E_WARNING(2) - unlink(/home/website/private/data/layout_cache/instance__structureddata__article-name--of-article__c81e728d9d4c2f636f067f89cc14862c.php): No such file or directory @ /home/website/private/system/classes/template.class.php line 2161  
Sun Jul 24 15:56:58 2022 - 20.124.16.205 - E_WARNING(2) - unlink(/home/website/private/data/layout_cache/english_utf-8/mobile/instance__likesblock__3__c81e728d9d4c2f636f067f89cc14862c__website_responsive.php): No such file or directory @ /home/website/private/system/classes/template.class.php line 2161  

This didn't happen on Geeklog 2.21 or PHP 7.3.

Geeklog.net seems to be fine though and it is using the same version and PHP version.

Any ideas @mystralkk

mystralkk commented 1 year ago

I guess Geeklog hasn't changed the way it handles cache files, so it is PHP that has changed how to deal with warnings and errors when files don't exist. To prevent this with PHP 8.1, we would have to make a temporary lock file at the very first of CTL_clearCacheDirectories() fnction and prevent other processes of the Web server from deleting cache files we are going to delete.

eSilverStrike commented 1 year ago

I don't remember clearing the cache when those errors where generated... I guess I could have (as it is the only time I believe CTL_clearCacheDirectories would be called). I will keep a closer eye next time I do it.

eSilverStrike commented 1 year ago

Just an FYI I've notice that Geeklog.net also ever once in a while gets this warning as well.

mystralkk commented 1 year ago

I tried to fix this issue with change set 8f28db39697bbab9001837fefe122e7ec3a6584d. Let's see how this will work out.

eSilverStrike commented 1 year ago

Will do. I'll upload the changes and see how the sites perform. I've had some work come in so I haven't obviously released Geeklog 2.2.2 yet.

eSilverStrike commented 1 year ago

Seeing a few warnings related to directories now:

Sat Sep 3 09:08:29 2022 - 147.92.153.1 - E_WARNING(2) - rmdir(/geeklogdirectories/data/layout_cache/dutch_utf-8): Directory not empty @ /geeklogdirectories/system/classes/template.class.php line 2170

mystralkk commented 1 year ago

Sorry, I misunderstood the return value of cache_clean_directories() and changed them.

eSilverStrike commented 1 year ago

Thanks for the fixes. I have no error messages at the moment in the log file but I did notice another problem.

After updating a staticpage that is cached, the cached file is not deleted on save (so a new cache file will be generated with the updated content when viewed again).

I had thought the save wasn't working but it was, I had to manually clear the cache for the entire website to view my page update.

This is also probably a problem with other items that are cached in a similar way like Articles, Blocks, etc... (have not tested myself)

Should also probably check to make sure items that cache files that are expired still get automatically deleted.

eSilverStrike commented 1 year ago

Can confirm this does affect blocks

eSilverStrike commented 1 year ago

I think I found the issue. Since cache_clean_directories is recursive and calls it self, setting the .lock file in the same directory would prevent future calls during the same process from deleting the required files and directories. The lock file is now set in the directory that is about to be deleted.

mystralkk commented 1 year ago

I guess you are right.