Wedge

Public area => Bug reports => The Pub => Archived fixes => Topic started by: Arantor on February 29th, 2012, 02:17 PM

Title: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on February 29th, 2012, 02:17 PM
As the example document indicates, this can actually affect Aeva so we do need to look into it, for cases where the file cache is used.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on March 1st, 2012, 12:38 AM
Two things occur to me about this.

Firstly we can of course patch cache_get_data and cache_put_data to do something with / (and \ potentially), but that won't prevent any issues if other illegal characters get inserted... I never checked what happened to something like " in a filename (which won't be legal on all filesystems) though I have a funny feeling it would be translated to its entity form (like I've seen with the shy entity)

Secondly, would it not be better to do some kind of hash on the key so that we don't inject actual names anyway?
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on March 1st, 2012, 07:47 AM
Second solution. Definitely. :)
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on March 1st, 2012, 10:21 AM
Question, are we talking about hashing the key all the time, or just the cases where it contains potentially awkward characters? If the latter, would it not be better to detect that actually in cache_*_data, and hash it there, rather than finding all the places where it's called with funny characters and hash before sending?
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 9th, 2012, 02:00 PM
Should definitely hash it all the time, I'm just trying to figure out the best way to do this since there's already an MD5 hash in the filename as it is.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 9th, 2012, 02:53 PM
Plus it might slow things down. Md5 is noticeably slow afaik?
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 9th, 2012, 02:57 PM
I've never heard of MD5 being slow, neither SHA1.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 9th, 2012, 09:38 PM
Base64 is faster innit? Were talking cache performance...
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 9th, 2012, 10:08 PM
Apart from the fact I don't know if base 64 is faster than md5 or not (I haven't benched it), I do know that base64 as PHP implements it can include +, = and / which may or may not be legal characters, and which doesn't leave us any closer to a workable solution. That would mean we'd end up with doing either a strtr or str_replace on top of the base64_encode.

What I'll do is benchmark MD5 vs SHA1 vs base64_encode for performance.
Posted: April 9th, 2012, 09:51 PM
Quote
Carrying out 500000 iterations

String: `something short`
    MD5: 0.62707901000977 seconds
    SHA1: 0.62861299514771 seconds
    B64: 0.44805788993835 seconds
    B64/sstrtr: 1.0246500968933 seconds
    B64/str_replace: 1.4543380737305 seconds

String: `something much much much much much longer that we can use to benchmark these things.`
    MD5: 0.67529892921448 seconds
    SHA1: 0.75934195518494 seconds
    B64: 0.47315502166748 seconds
    B64/sstrtr: 1.0639209747314 seconds
    B64/str_replace: 1.5031769275665 seconds

String: `something impossibly and unrealistically long, after longer than the typical cache key will be but just in case it is worth having an idea of relative performance`
    MD5: 0.74138998985291 seconds
    SHA1: 0.8517210483551 seconds
    B64: 0.50031614303589 seconds
    B64/sstrtr: 1.154757976532 seconds
    B64/str_replace: 1.6336131095886 seconds
Code: [Select]
<?php

$strings 
= array(
'something short',
'something much much much much much longer that we can use to benchmark these things.',
'something impossibly and unrealistically long, after longer than the typical cache key will be but just in case it is worth having an idea of relative performance',
);

$iters 500000;

echo 
'Carrying out '$iters' iterations<br>';

foreach (
$strings as $str)
{
echo '<hr><br>String: `'$str'`<br>';

$time_start microtime(true);
for ($i 0$i $iters$i++)
$dummy md5($str);
$time_end microtime(true);
echo '    MD5: '$time_end $time_start' seconds<br>';

$time_start microtime(true);
for ($i 0$i $iters$i++)
$dummy sha1($str);
$time_end microtime(true);
echo '    SHA1: '$time_end $time_start' seconds<br>';

$time_start microtime(true);
for ($i 0$i $iters$i++)
$dummy base64_encode($str);
$time_end microtime(true);
echo '    B64: '$time_end $time_start' seconds<br>';

$time_start microtime(true);
for ($i 0$i $iters$i++)
$dummy strtr(base64_encode($str), '+/=''-__');
$time_end microtime(true);
echo '    B64/sstrtr: '$time_end $time_start' seconds<br>';

$time_start microtime(true);
$s = array('+''/''=');
$r = array('-''_''_');
for ($i 0$i $iters$i++)
$dummy str_replace($s$rbase64_encode($str));
$time_end microtime(true);
echo '    B64/str_replace: '$time_end $time_start' seconds<br>';
}

It's crude but illustrates the relative performance. B64 is fastest - if we can rely on it never generating invalid characters in the keys, which we can't.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 10th, 2012, 10:33 AM
I don't think + and = characters are invalid in any way, really...?! Whatever the file system... It's just something that's included in any standard.
If anything, to me it's less scary than the (infinitesimal) chance of collision a md5 hash may generate...
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 10th, 2012, 12:16 PM
= isn't really an issue but + certainly used to be in Windows (though I think it's allowed in NTFS)

If you want to be sure about avoiding collisions and still fixing the problem and still being fast, instead fix where the cache key contains /... The only move is not to play.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 10th, 2012, 12:44 PM
Windows 95+ accept + signs, it's only DOS (8.3) that won't take them... And I don't know of TOO MANY servers that run on Windows NT 3.1 ;)

Ah, still love my War Game references :P
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 10th, 2012, 01:09 PM
Windows 95 doesn't properly accept them because they are also valid syntax for its copy command to merge files, i.e. copy file1+file2.txt merged-file.txt. (Been bitten by this in the past)

It's kind of irrelevant though... + and = aren't the killers, / is, which brings us back to where we were before. I can rebenchmark it just replacing that one character out and see what difference it makes?

On a side note it does sort of challenge the long-held view that str_replace is faster than strtr...
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 10th, 2012, 10:30 PM
Yup.
It's still lightning fast though.

Trying adding a strpos before, too! It's pretty much a free call. Really.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 10th, 2012, 10:50 PM
So, then, strpos for '/', base64 if found, if not leave it as is?
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 10th, 2012, 11:14 PM
Not sure base64 is that necessary if we do that.

Oh, and best way to benchmark is prolly to generate a random string on every loop. I'm sure php would optimize it otherwise.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 11th, 2012, 12:15 AM
I'm not sure it is caching anything. The overhead of caching would be a significant slowdown.

I think we do need to base64 it at that point, we can't safely replace that character, it's a collision risk.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: nend on April 16th, 2012, 03:21 AM
Bickering about a bug I reported to SMF, lol.

So far all I know about it is it affects file caching for sure, as to any other caching means, I am not sure. So if it doesn't affect any of the other systems then it would be appropriate not to make the key safe for them since they are able to handle it. This is speculation since I don't know how the other cache systems work.

However one could argue it is up to the developer to send safe keys to the cache but I am sure some will not follow.

IMHO base64 is just going to cause more problems, since your going to have to check the output of it to make sure that it didn't make illegal characters in the key, so basically it will put you back to where you started.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: nend on April 16th, 2012, 03:32 AM
My test results, I added a few on there, it looks like strtr by itself would be allot better. :cool:

PHP 5.3 on grid/cloud hosting.
Quote
Carrying out 500000 iterations

String: `something short`
MD5: 0.34987902641296 seconds
SHA1: 0.48932695388794 seconds
B64: 0.16412401199341 seconds
B64/sstrtr: 0.57090711593628 seconds
B64/str_replace: 0.92343997955322 seconds
sstrtr: 0.41409516334534 seconds
str_replace: 0.85998892784119 seconds

String: `something much much much much much longer that we can use to benchmark these things.`
MD5: 0.48175501823425 seconds
SHA1: 0.70720291137695 seconds
B64: 0.23448801040649 seconds
B64/sstrtr: 0.6997401714325 seconds
B64/str_replace: 1.0725769996643 seconds
sstrtr: 0.48645901679993 seconds
str_replace: 0.88212299346924 seconds

String: `something impossibly and unrealistically long, after longer than the typical cache key will be but just in case it is worth having an idea of relative performance`
MD5: 0.52688503265381 seconds
SHA1: 0.93148612976074 seconds
B64: 0.32354092597961 seconds
B64/sstrtr: 0.91212201118469 seconds
B64/str_replace: 1.3229742050171 seconds
sstrtr: 0.60456418991089 seconds
str_replace: 1.0461859703064 seconds
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 16th, 2012, 03:46 AM
Quote
Bickering about a bug I reported to SMF, lol.
Oh, there's no argument that there's a bug. It's how best to fix it, knowing that caching should be as fast as possible while not compromising functionality.
Quote
So far all I know about it is it affects file caching for sure, as to any other caching means, I am not sure.
As far as I know, memcache(d) and APC do not care and neither uses file based storage in any fashion and as such it doesn't matter.
Quote
However one could argue it is up to the developer to send safe keys to the cache but I am sure some will not follow.
In the case of SMF+Aeva, that's a valid proposition, because it's essentially a non-compliant mod rather than a core feature, but in Wedge's case, it's a core feature that we have to contend with and it would be better to fix it at the cache level rather than the cache caller.
Quote
My test results, I added a few on there, it looks like strtr by itself would be allot better.
Except that we can't use it, because of the inherent risk of collision. If you have path/file.ext and strtr the / out to _ (or indeed any other character, but we'll use _ for the sake of argument), path/file.ext and path_file.ext both resolve to the same cache key, and since the root name used is the album name, users have some control over this process. I'm not saying that it's a direct vulnerability, but anything that a user can (relatively) trivially manipulate in this fashion is a bad idea.

On the other hand, MD5 is faster even than strtr and while it does carry a collision risk, I'd argue that it's actually much less likely than strtr especially as it can't be manipulated as easily by the user.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 16th, 2012, 06:45 PM
As I didn't read the original report, I didn't even know there was a problem with AeMe...
Blame any Aeva cache issues on Dragooon, he did it all :niark:

There's also Subs-Sounds.php that clearly uses slashes in the key...

I'll still cast my vote on base64_encode (alone), based on what was discussed.

Now... I'm looking into the actual caching code, and here's the thing.

Code: [Select]
$key = md5($boardurl . filemtime($sourcedir . '/Collapse.php')) . '-Wedge-' . strtr($key, ':', '-');

It's ALREADY doing both a md5 (on the prefix though!), and on the key (to replace ":").
So it can easily be turned into strtr($key, ':/', '--') for speed reasons...
However, it would make more sense to 'simply' put everything into the md5() call. I see no reason not to do so...
Also, I'm not exactly sure why it absolutely needs to retrieve filemtime here, is it for security reasons? (i.e. not allowing a user to find the correct URL for the cache...)
But we *already* have an htaccess file that prevents directly viewing php files...

(Plus, I've always been bothered by this 'touch' on Collapse.php -- previously on Load.php in SMF which is a VERY bad idea, because that file is critical and often modified...)

Suggesting this as replacement, then...

Code: [Select]
$key = base64_encode($key);

And voilĂ , problem solved... And supercharged cache ;)
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Dragooon on April 16th, 2012, 07:22 PM
I'm fairly sure SMG had no cache when I made it...or did it?
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 16th, 2012, 07:57 PM
Quote from Dragooon on April 16th, 2012, 07:22 PM
I'm fairly sure SMG had no cache when I made it...or did it?
What I know is that I had absolutely no knowledge of SMF2 caching until I started work on Wedge ;)
Well, I knew it existed (and was my prime reason to use SMF2), but I'd never looked into the code, it was too esoteric for me.

One could say, that basically when you were 13, you were way more knowledgeable about SMF programming than I was. And I'm 20 years older than you :P
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 16th, 2012, 07:58 PM
Quote
Also, I'm not exactly sure why it absolutely needs to retrieve filemtime here, is it for security reasons? (i.e. not allowing a user to find the correct URL for the cache...)
Forcing cache expiry. Cleaning the cache updates the filemtime on Collapse.php, so that all the file caches are invalidated at once in case the files themselves didn't get removed.
Quote
And voilĂ , problem solved... And supercharged cache
And you also have no reliable way to force cache expiry short of deleting files (which has been a source of contention in the past anyway)
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 16th, 2012, 09:23 PM
So, just keeping an unencoded filemtime at the start, the rest should be fine...?
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 16th, 2012, 11:17 PM
Well, the md5 does have a security aspect to it as well, because not all servers listen to the contents of the .htaccess files (like IIS, nginx, some configurations of Apache)

Ideally I'd prefer ot keep that aspect of it in place unless there's a good reason not to (and right now, the slight performance increase vs the security aspect isn't quite enough)
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 16th, 2012, 11:28 PM
Instead of the filemtime, I'd really (really) rather we have a $settings variable that we increment when we ask for a cache flush...
I know that most file operations are cached in PHP for some time, so a filemtime shouldn't be expensive at all, but I'd rather not count on it. I'm still considering adding an option to disable file date checking for CSS and JS files, which I'm sure would save more than a few milliseconds on each page load...

I don't really see security being any better if using md5() over base64. What can happen? Someone trying to repeatedly run a check on a URL by decreasing the time from now to a week ago or something...? It's tantamount to brute-forcing a md5() as well, if you ask me...

In any case, I don't see the need for storing $boardurl in the file name. And the base64 encoding should replace the strtr, at least that is proven to be as fast, or faster.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 16th, 2012, 11:33 PM
Quote
Instead of the filemtime, I'd really (really) rather we have a $settings variable that we increment when we ask for a cache flush...
There is, $settings['settings_updated']. But the settings are also cached...
Quote
I don't really see security being any better if using md5() over base64. What can happen?
I'm not saying md5 vs base64, I'm saying something vs nothing where the result is not trivially guessable by a hacker.
Quote
In any case, I don't see the need for storing $boardurl in the file name. And the base64 encoding should replace the strtr, at least that is proven to be as fast, or faster.
But the base64 can still generate characters that are invalid. AND there are other cases where invalid filename characters are sent anyway, like : which isn't valid on Windows. Now, the base64 will fix that but you will still occasionally get / in the resultant base64 encoding, so you don't save anything there either.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: nend on April 17th, 2012, 06:12 AM
How about convert the string to something that can't possibly be a collision risk and file name safe. I just thought of this while writing this post and ran a test in the middle of the post, bin2hex. From test I am getting real fast speeds from this function, the only problem I forsee though is filename limits.

Maybe key compression of some sort if the key is too long or maybe say a folder structure for long keys where the key can be continued over the span of multiple folders.

Test results
Quote
Carrying out 500000 iterations

String: `something short`
MD5: 0.32972002029419 seconds
SHA1: 0.47672295570374 seconds
B64: 0.17632007598877 seconds
B64/strtr: 0.57628583908081 seconds
B64/str_replace: 0.93950510025024 seconds
bin2hex: 0.16528415679932 seconds

String: `something much much much much much longer that we can use to benchmark these things.`
MD5: 0.42671203613281 seconds
SHA1: 0.69267106056213 seconds
B64: 0.22752213478088 seconds
B64/strtr: 0.70388197898865 seconds
B64/str_replace: 1.0751059055328 seconds
bin2hex: 0.25826096534729 seconds

String: `something impossibly and unrealistically long, after longer than the typical cache key will be but just in case it is worth having an idea of relative performance`
MD5: 0.51122808456421 seconds
SHA1: 0.90426898002625 seconds
B64: 0.30805087089539 seconds
B64/strtr: 0.89947199821472 seconds
B64/str_replace: 1.3907599449158 seconds
bin2hex: 0.33286499977112 seconds
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 17th, 2012, 02:26 PM
To be honest, bin2hex is only a percentage longer than base64 anyway, but it's certainly the fastest of the practical options. Filename length is only an issue with long keys - which is mostly related to media where this all started :/
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 17th, 2012, 07:03 PM
Quote from Arantor on April 16th, 2012, 11:33 PM
There is, $settings['settings_updated']. But the settings are also cached...
My, you always have an answer to everything... :lol:
So, in order to retrieve the cache hash, I would need to first get the cache hash and then retrieve the cache based on that cache hash... THEN I can know what the cache hash is :^^;:
Quote
I'm not saying md5 vs base64, I'm saying something vs nothing where the result is not trivially guessable by a hacker.
Hmm, I was thinking... md5() is a 128-bit number, so it's something like at least a billion billion billion billion... Thinking about it, since we can barely have more than 2000 files in a folder, it's very, very unlikely to get a collision -- ever... No?
Quote
But the base64 can still generate characters that are invalid.
I forgot about the slash being a valid base64 char. Oh, my... They should have chosen something else! It's not like there are so few valid characters for an URI...
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 17th, 2012, 07:11 PM
Quote from nend on April 17th, 2012, 06:12 AM
How about convert the string to something that can't possibly be a collision risk and file name safe. I just thought of this while writing this post and ran a test in the middle of the post, bin2hex. From test I am getting real fast speeds from this function, the only problem I forsee though is filename limits.
Hmm, I like that... bin2hex seems to be fast indeed.
I was also looking into sha1(), crypt('sha256') and pack() (there are plenty of options to convert these), or even using base_convert() to automatically use alphanumeric characters only...
But bin2hex could be just as simple :P
Although not as secure as a md5() on boardurl.filemtime...

Oh, Pete -- how about we calculate that md5 hash only ONCE per page...? It seems stupid not to do it. We could simply store it in $context['cache_hash'] or something... If empty, just fill it in...
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 17th, 2012, 08:35 PM
Quote
My, you always have an answer to everything...
Well, I've had to work with it in the past, hence I did know about it. Plus there are plenty of places where it actually checks settings_updated to avoid calling on cache (usually where on level 2+ where the cache key is the only thing, there won't be a way of invalidating it so easily)
Quote
So, in order to retrieve the cache hash, I would need to first get the cache hash and then retrieve the cache based on that cache hash... THEN I can know what the cache hash is :^^;:
It is sort of complicated, yes :P
Quote
Hmm, I was thinking... md5() is a 128-bit number, so it's something like at least a billion billion billion billion... Thinking about it, since we can barely have more than 2000 files in a folder, it's very, very unlikely to get a collision -- ever... No?
It's not quite like that, no. The problem with cache keys is that they're all in the one folder - everything goes into $cachedir, and everything would notionally get the same md5() process applied, so you're not just considering collisions across the namespace of a single album's files, but collisions across everything that the md5() is applied to, which is potentially every media item (since we only need apply the md5 if there isn't a / in the supplied cache key)

That said, md5 might be 128 bits, but it's not 128-bit wide in collision cases. It was proved a few years ago that for collision purposes, the keyspace isn't 2^128 but more like 2^40 due to weaknesses in the way it's generated.
Quote
I forgot about the slash being a valid base64 char. Oh, my... They should have chosen something else! It's not like there are so few valid characters for an URI...
Actually, there aren't that many characters truly valid in a URI, the vast majority of them have... extra meanings, and are normally just %-encoded instead.
Quote
Hmm, I like that... bin2hex seems to be fast indeed.
I was also looking into sha1(), crypt('sha256') and pack() (there are plenty of options to convert these), or even using base_convert() to automatically use alphanumeric characters only...
But bin2hex could be just as simple :P
Although not as secure as a md5() on boardurl.filemtime...
Certainly it's fast, and for short keys it's faster than even base64. I'd avoid crypt, though, there were issues with it and related functions in 5.3.7, pack() is really just a super-sized version of what bin2hex is doing anyway, heh.

You're right, it's not as secure as md5ing the filemtime, and that's reasonably important for the sake of safety.
Quote
Oh, Pete -- how about we calculate that md5 hash only ONCE per page...? It seems stupid not to do it. We could simply store it in $context['cache_hash'] or something... If empty, just fill it in...
Works for me. :)
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 18th, 2012, 05:44 PM
Quote from Arantor on April 17th, 2012, 08:35 PM
It's not quite like that, no. The problem with cache keys is that they're all in the one folder - everything goes into $cachedir, and everything would notionally get the same md5() process applied, so you're not just considering collisions across the namespace of a single album's files, but collisions across everything that the md5() is applied to, which is potentially every media item (since we only need apply the md5 if there isn't a / in the supplied cache key)
We could also 'simply' create subfolders in /cache/ named after the cache hash... And store files in them (without the starting hash, of course.)
At least it wouldn't break/kill the cache (at least too soon) if files can't be removed.
Quote
That said, md5 might be 128 bits, but it's not 128-bit wide in collision cases. It was proved a few years ago that for collision purposes, the keyspace isn't 2^128 but more like 2^40 due to weaknesses in the way it's generated.
I see.
Quote
Actually, there aren't that many characters truly valid in a URI, the vast majority of them have... extra meanings, and are normally just %-encoded instead.
I guess we could also use urlencode() or something... :lol:
Quote
Quote
Oh, Pete -- how about we calculate that md5 hash only ONCE per page...? It seems stupid not to do it. We could simply store it in $context['cache_hash'] or something... If empty, just fill it in...
Works for me. :)
That's a pointless micro-optimization, in the end. It's obvious that PHP caches that value.
I saved the hash into $settings['cache_hash'] (I know it's not a good idea to use that global, but I don't want to pull $context into itself within the cache functions... Bad karma?), and did some benchmarking. (1000 calls to retrieve 'settings', which is the bigger cache file...)

SVN version with md5, filemtime and base64: 0.45s in average (Which is probably already much faster than in SMF...)
My version with cache hash and bin2hex: 0.44s in average

I'm not kidding you...
I also tried removing the @ in front of the include call, to no effect.
Removing the include entirely gave me results between 0.01s and 0.03s, very unstable, so it's hard to determine which is faster. So I guess I'll still commit this, but not in an enthusiastic way :P
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 18th, 2012, 07:23 PM
Quote
We could also 'simply' create subfolders in /cache/ named after the cache hash... And store files in them (without the starting hash, of course.)
At least it wouldn't break/kill the cache (at least too soon) if files can't be removed.
There are problems with doing that, namely that for every folder, you'd have to make sure that index.php/.htaccess were also added to each folder. Honestly it would be better not to do that and flatten its structure.
Quote
I guess we could also use urlencode() or something...
Is % a valid filename character? ;)
Quote
That's a pointless micro-optimization, in the end. It's obvious that PHP caches that value.
I saved the hash into $settings['cache_hash'] (I know it's not a good idea to use that global, but I don't want to pull $context into itself within the cache functions... Bad karma?), and did some benchmarking. (1000 calls to retrieve 'settings', which is the bigger cache file...)
Interesting. I guess it's hard to really optimise something like that properly.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 18th, 2012, 07:40 PM
Quote from Arantor on April 18th, 2012, 07:23 PM
There are problems with doing that, namely that for every folder, you'd have to make sure that index.php/.htaccess were also added to each folder.
Sure. Of course people would first have to be able to find the folder... ;)
And if htaccess works -- it's only needed in the parent folder anyway.
Quote
Is % a valid filename character? ;)
If it isn't, I'll eat you! :ph34r:
Quote
Interesting. I guess it's hard to really optimise something like that properly.
include() can be (relatively) slow. Heck, simply loading SMF/Wedge's basic files (load, subs...) easily takes a few tenths of a second!
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 18th, 2012, 07:41 PM
Quote
And if htaccess works -- it's only needed in the parent folder anyway.
That's not strictly true. There are configurations of Apache that do not allow cascading. And not all servers run Apache (I'm looking at moving to nginx, for example)
Quote
include() can be (relatively) slow. Heck, simply loading SMF/Wedge's basic files (load, subs...) easily takes a few tenths of a second!
Yeah, I know. Part of that is the pure I/O and part of that is the parsing stage.
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Nao on April 18th, 2012, 07:44 PM
Quote from Arantor on April 18th, 2012, 07:41 PM
That's not strictly true. There are configurations of Apache that do not allow cascading. And not all servers run Apache (I'm looking at moving to nginx, for example)
Why the hell do programmers like to fuck with us every once in a while? :(
Quote
Yeah, I know. Part of that is the pure I/O and part of that is the parsing stage.
That's where php bytecode cache (or whatever it's called) probably helps the most...
Title: Re: SMF bug 4956 (slash in cache key causes cache to fail)
Post by: Arantor on April 18th, 2012, 07:47 PM
Quote
Why the hell do programmers like to fuck with us every once in a while?
Apache is... interesting.
Quote
That's where php bytecode cache (or whatever it's called) probably helps the most...
Oh hell yes. Mind you if you're using that, you almost certainly get a proper memory cache anyway.