wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Failed to open stream: File name too long

Open logdirect opened this issue 4 years ago • 35 comments

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.

logdirect avatar Mar 17 '20 10:03 logdirect

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

GeekPress avatar Mar 20 '20 21:03 GeekPress

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 avatar Mar 23 '20 09:03 crystinutzaa

@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?

GeekPress avatar Mar 23 '20 10:03 GeekPress

@logdirect On this customer website, is there any value added in the "cache query strings" field in advanced cache settings of WP Rocket?

remyperona avatar Mar 23 '20 13:03 remyperona

@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.

logdirect avatar Mar 26 '20 14:03 logdirect

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.

remyperona avatar Mar 26 '20 18:03 remyperona

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 ..

logdirect avatar Mar 27 '20 12:03 logdirect

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

GeekPress avatar May 07 '20 13:05 GeekPress

Related ticket: https://secure.helpscout.net/conversation/1159627993/163879?folderId=2952229

mifrero avatar May 09 '20 12:05 mifrero

Related ticket: https://secure.helpscout.net/conversation/1161687679/0/?folderId=3572910

juricazuanovic avatar May 13 '20 18:05 juricazuanovic

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.

webtrainingwheels avatar Jun 07 '20 00:06 webtrainingwheels

Related: https://secure.helpscout.net/conversation/1190760775/171812?folderId=2952229

mifrero avatar Jun 11 '20 17:06 mifrero

Related ticket: https://secure.helpscout.net/conversation/1216324927/178135/

vmanthos avatar Jul 06 '20 08:07 vmanthos

Related ticket: https://secure.helpscout.net/conversation/1220241849/179237?folderId=1213662

WordPresseur avatar Jul 10 '20 12:07 WordPresseur

related ticket: https://secure.helpscout.net/conversation/1226942553/180611?folderId=273761

alfonso100 avatar Jul 16 '20 15:07 alfonso100

Related ticket: https://secure.helpscout.net/conversation/1228018429/180853/

viobru avatar Jul 17 '20 15:07 viobru

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.

webtrainingwheels avatar Jul 21 '20 23:07 webtrainingwheels

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.

webtrainingwheels avatar Aug 10 '20 18:08 webtrainingwheels

Another one with GDPR plugin and long name due to the 25 cookies added in the filename: https://secure.helpscout.net/conversation/1325744198/207777/

NataliaDrause avatar Nov 02 '20 09:11 NataliaDrause

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

sandyfigueroa avatar Nov 26 '20 15:11 sandyfigueroa

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:

jorgemartine00 avatar Feb 16 '21 21:02 jorgemartine00

Related ticket: https://secure.helpscout.net/conversation/1441885630/243995?folderId=3326173

vmanthos avatar Mar 03 '21 07:03 vmanthos

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.

DahmaniAdame avatar Mar 16 '21 06:03 DahmaniAdame

Related ticket - https://secure.helpscout.net/conversation/1450393190/246384/

DahmaniAdame avatar Mar 16 '21 06:03 DahmaniAdame

Related ticket: https://secure.helpscout.net/conversation/1454633232/247895

vmanthos avatar Mar 17 '21 10:03 vmanthos

Related ticket: https://secure.helpscout.net/conversation/1453807106/247624/

jorgemartine00 avatar Mar 21 '21 18:03 jorgemartine00

https://secure.helpscout.net/conversation/1472233949/252695?folderId=377611

webtrainingwheels avatar Apr 07 '21 19:04 webtrainingwheels

Another case. related to Arabic characters encoding: https://secure.helpscout.net/conversation/1558651034/275746?folderId=4130695

alfonso100 avatar Jul 01 '21 14:07 alfonso100

Related ticket: https://secure.helpscout.net/conversation/1583373050/283180?folderId=2135277

This is on Azure/IIS.

vmanthos avatar Jul 27 '21 13:07 vmanthos

Related https://secure.helpscout.net/conversation/1687793200/306017/

camilamadronero-zz avatar Nov 05 '21 15:11 camilamadronero-zz