wp-rocket
wp-rocket copied to clipboard
Failed to open stream: File name too long
We are using WP-Rocket Plugin on a customer website. Since the last update, it seems that the naming conventions for the cache files have been changed. We are having lots and lots of these errors:
Stack trace E_WARNING: copy(/var/www/html/wp-content/cache/wp-rocket/www.astrology-psychic-reading.com-myemailaddress@example.net-5cdbc7c23e4a8161374624/fi/the_great_vision_from_the_quantum_pendulum_2003_en/lv/#k=eyJhbGciOiJIUzI1NiJ9.eyJpZCI6OTUzNDEsImtleSI6Ijg1ZGM0ZTE2NTc1NThjYzZlMGU3NTM1ZmIzNmVmYjU3In0.7I1EGjzMv_f1N7xHAlWbkcJOpO49LVfI6UkuZg8dpUw&mname=UzCJhMgB30++xmUH9P3XnYavt+Yea7rSt%2fqNzyJxV+A%3d&va3=epbYIGPLDid%2fpDHgM39Nng%3d%3d&va4=1mDowu%2fZfpaMRgcZyqg+kA%3d%3d/index-https-webp.html_gzip_temp): failed to open stream: File name too long in copy called at /var/www/html/wp-admin/includes/class-wp-filesystem-direct.php (281) in WP_Filesystem_Direct::copy called at /var/www/html/wp-admin/includes/class-wp-filesystem-direct.php (309) in WP_Filesystem_Direct::move called at /var/www/html/wp-content/plugins/wp-rocket/inc/classes/Buffer/class-cache.php (363) in WP_Rocket\Buffer\Cache::write_cache_file called at /var/www/html/wp-content/plugins/wp-rocket/inc/classes/Buffer/class-cache.php (308) in WP_Rocket\Buffer\Cache::maybe_process_buffer called at ? (?) in ob_end_flush called at /var/www/html/wp-includes/functions.php (4552) in wp_ob_end_flush_all called at /var/www/html/wp-includes/class-wp-hook.php (288) in WP_Hook::apply_filters called at /var/www/html/wp-includes/class-wp-hook.php (312) in WP_Hook::do_action called at /var/www/html/wp-includes/plugin.php (478) in do_action called at /var/www/html/wp-includes/load.php (947) in shutdown_action_hook called at ? (?)
We are seeing more than 8000 occurences over 24 hours. The stack traces are of course slightly different, but the error message is the same. The cache file which is generated is too long.
There is a limit on the filename length when using copy
and other PHP functions. It seems to be 256 characters.
Steps to reproduce
- Create a post with an URL longer than 256 characters
- Visit the uncached version of this post
I took a look at this one and it seems that something else might cause this. I cannot recreate it on a clean Wordpress installation and in the function which generates the Wordpress slug this function: wp_unique_post_slug
will automatically truncate the slug at 200chars.
https://developer.wordpress.org/reference/functions/wp_unique_post_slug/
The error shows a really interesting URL:
/var/www/html/wp-content/cache/wp-rocket/www.astrology-psychic-reading.com-myemailaddress@example.net-5cdbc7c23e4a8161374624/fi/the_great_vision_from_the_quantum_pendulum_2003_en/lv/#k=eyJhbGciOiJIUzI1NiJ9.eyJpZCI6OTUzNDEsImtleSI6Ijg1ZGM0ZTE2NTc1NThjYzZlMGU3NTM1ZmIzNmVmYjU3In0.7I1EGjzMv_f1N7xHAlWbkcJOpO49LVfI6UkuZg8dpUw&mname=UzCJhMgB30++xmUH9P3XnYavt+Yea7rSt%2fqNzyJxV+A%3d&va3=epbYIGPLDid%2fpDHgM39Nng%3d%3d&va4=1mDowu%2fZfpaMRgcZyqg+kA%3d%3d/index-https-webp.html_gzip_temp
I think this type should be truncated fully, but we need to identify which might cause it:
#k=eyJhbGciOiJIUzI1NiJ9.eyJpZCI6OTUzNDEsImtleSI6Ijg1ZGM0ZTE2NTc1NThjYzZlMGU3NTM1ZmIzNmVmYjU3In0.7I1EGjzMv_f1N7xHAlWbkcJOpO49LVfI6UkuZg8dpUw&mname=UzCJhMgB30++xmUH9P3XnYavt+Yea7rSt%2fqNzyJxV+A%3d&va3=epbYIGPLDid%2fpDHgM39Nng%3d%3d&va4=1mDowu%2fZfpaMRgcZyqg+kA%3d%3d
@Tabrisrp , @hellofromtonya , @GeekPress , @Screenfeed ideas?
@crystinutzaa I have no idea how the query string is added. But it seems to be the cause of the issue. Don't we clean the URL before to copy the final caching file?
@logdirect On this customer website, is there any value added in the "cache query strings" field in advanced cache settings of WP Rocket?
@Tabrisrp There is a whole list of parameters in there, such as: k partner media campaignarea campaign subid subid2 subid3 subid4 subid5 gclid theme offertype context leadowner transactionid
I think there is just not enough cleaning on the final file name, so very long urls will give these errors.
With query strings caching enabled like that, there is a risk of long filenames, because any URL containing at least one of those parameters will be cached.
Cutting the filename would introduce the risk of incorrectly matching URLs with cache files, serving the cache when it shouldn't.
Before running the last upgrade of WP-Rocket it has been working correctly. So my guess would be that something has changed.
Wouldn't it be simpler to hash all those parameters or compact them somehow in order to have a shorter filename? Maybe have the cache files organized in folders? Just searching ..
Customer to follow up after release
- https://secure.helpscout.net/conversation/1151812330/161942?folderId=2135277
- https://secure.helpscout.net/conversation/1151999488/161997?folderId=2952229
- https://secure.helpscout.net/conversation/1109033877/151549?folderId=273768
Related ticket: https://secure.helpscout.net/conversation/1159627993/163879?folderId=2952229
Related ticket: https://secure.helpscout.net/conversation/1161687679/0/?folderId=3572910
Related: https://secure.helpscout.net/conversation/1185845740/170635?folderId=377611 In this case it seems directly related to the Greek language URLs being used, which are converted to very long urls when encoded. [customer can't provide access] Server is IIS in this case.
Related: https://secure.helpscout.net/conversation/1190760775/171812?folderId=2952229
Related ticket: https://secure.helpscout.net/conversation/1216324927/178135/
Related ticket: https://secure.helpscout.net/conversation/1220241849/179237?folderId=1213662
related ticket: https://secure.helpscout.net/conversation/1226942553/180611?folderId=273761
Related ticket: https://secure.helpscout.net/conversation/1228018429/180853/
The case @viobru has referenced above is related to dynamic cookies set by this GDPR plugin -https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/plugins/cookies/gdpr.php There are 27 allowed cookies and they are all being appended to the cache file name, triggering the problem. Customer says it's related to the CleanTalk plugin but it's not clear just yet exactly how it's interfering.
The customer referenced here, https://github.com/wp-media/wp-rocket/issues/2440#issuecomment-640139245, provided the following update:
I just wanted to let you know that with PHP 7.4.9 the PHP Warnings are gone. Of course I'm not sure if this is related to your latest release or if it is truely a PHP 7.4.9 issue but in any case, I hope it helps you.
Another one with GDPR plugin and long name due to the 25 cookies added in the filename: https://secure.helpscout.net/conversation/1325744198/207777/
Another case: https://secure.helpscout.net/conversation/1348697237/216284/
In this case, the user is using non-English language so, the url is expanded (including the querystring)
Example:
https://mrsasmaa.com/files/المراحل-التعليمية/?cat=001-الصف-الأول&material=اللغة%20العربية
Becomes: https://mrsasmaa.com/files/%d8%a7%d9%84%d9%85%d8%b1%d8%a7%d8%ad%d9%84-%d8%a7%d9%84%d8%aa%d8%b9%d9%84%d9%8a%d9%85%d9%8a%d8%a9/?cat=001-%d8%a7%d9%84%d8%b5%d9%81-%d8%a7%d9%84%d8%a3%d9%88%d9%84&material=%D8%A7%D9%84%D9%84%D8%BA%D8%A9%20%D8%A7%D9%84%D8%B9%D8%B1%D8%A8%D9%8A%D8%A9
So the folder / path is called something similar to: %d8%a7%d9%84%d9%85%d8%b1%d8%a7%d8%ad%d9%84-%d8%a7%d9%84%d8%aa%d8%b9%d9%84%d9%8a%d9%85%d9%8a%d8%a9/?cat=001-%d8%a7%d9%84%d8%b5%d9%81-%d8%a7%d9%84%d8%a3%d9%88%d9%84&material=%D8%A7%D9%84%D9%84%D8%BA%D8%A9%20%D8%A7%D9%84%D8%B9%D8%B1%D8%A8%D9%8A%D8%A9
In reference to this: https://github.com/wp-media/wp-rocket/issues/2440#issuecomment-671521721
It seems that it could be fixed in version 7.4.9: https://prnt.sc/vqngd8, https://prnt.sc/vqnglh
related https://secure.helpscout.net/conversation/1425890962/239472 I think this one is related to what Sandy mentioned above where the site's default language is not English thus the URL being generated is similar to this 2021/02/11 03:09:50 [error] 275 # 275: * 502264 FastCGI sent in stderr:" PHP message: PHP Warning: copy (PATH / wp-content / cache / wp- rocket / candiashop.gr / el /% cf% 87% ce% b5% ce% b9% cf% 81% ce% bf% cf% 80% ce% bf% ce% b9% ce% b7% cf% 84% ce % b1-% ce% ba% ce% bf% cf% 83% ce% bc% ce% b7% ce% bc% ce% b1% cf% 84% ce% b1 /% cf% 83% ce% ba% ce % bf% cf% 85% ce% bb% ce% b1% cf% 81% ce% b9% ce% ba% ce% b9% ce% b1-% ce% ba% cf% 81% ce% b5% ce% bc% ce% b1% cf% 83% cf% 84% ce% b1-% ce% bc% ce% b5-% ce% bc% ce% b1% cf% 81% ce% b3% ce% b1% cf% 81% ce% b9% cf% 84% ce% b1% cf% 81% ce% b9% ce% b1-% ce% ba% ce% bf% ce% bd% cf% 84% ce% b1-% cf% 83% cf% 87% ce% b7% ce% bc% ce% b1-% ce% ba% ce% bb% ce% b1% ce% b4% ce% b9% ce% bf% cf% 85-% ce% b2% ce% b5% cf% 81% cf% 85% ce% ba% ce% bf% ce% ba% ce% b9% ce% b1-% ce% b9% ce% b4% ce% b9% ce% b1 % ce% b9% cf% 84% ce% b5% cf% 81% ce% b1-% cf% 87% ce% b5% ce% b9% cf% 81% ce% bf% cf% 80% ce% bf% ce% b9% ce% b7% cf% 84% ce% b1-3039 / index-mobile-https.html_temp): failed to open stream: File name too long in PATHwp-admin / includes / class-wp-filesystem-direct .php on line 309PHP message:
Related ticket: https://secure.helpscout.net/conversation/1441885630/243995?folderId=3326173
Related ticket - https://secure.helpscout.net/conversation/1450270777/246311/ The long URL will cause CPCSS to fail if the sample page WP Rocket picks up to generate CPCSS happens to have a long (converted) URL.
Related ticket - https://secure.helpscout.net/conversation/1450393190/246384/
Related ticket: https://secure.helpscout.net/conversation/1454633232/247895
Related ticket: https://secure.helpscout.net/conversation/1453807106/247624/
https://secure.helpscout.net/conversation/1472233949/252695?folderId=377611
Another case. related to Arabic characters encoding: https://secure.helpscout.net/conversation/1558651034/275746?folderId=4130695
Related ticket: https://secure.helpscout.net/conversation/1583373050/283180?folderId=2135277
This is on Azure/IIS.
Related https://secure.helpscout.net/conversation/1687793200/306017/