Forum Moderators: phranque

Message Too Old, No Replies

Using FilesMatch

         

csdude55

9:21 pm on Apr 30, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



On every PHP script of my site, I use require_once 'variables.php';. Inside of variables.php, I have a switch-case that's 4.2kb in size; it looks at the domain, and sets variables based on which domain the user is using. I set them as a SESSION variable so (in theory) it only runs once per session, but it's still an extra 4kb on each page.

I COULD move this to .htaccess (and eventually httpd.conf), where I already test the domains and set up rewrites, anyway. I think it would be faster to process, but I don't want to add 4kb+ to the server configuration if it's going to run unnecessarily on every HTTP request. These variables only need to be set on PHP scripts, not images, css, js, etc.

Would something like this work the way it looks? If so, do you guys and gals think it would be faster to set the variables this way instead of via PHP?

RewriteEngine on

# Cache for 1 year; 1 month = 2628000
<FilesMatch "load_subnav\.php|\.(ico|css|js|jpg|jpeg|png|gif)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

# Touch icons
RewriteRule ^apple-touch-icon.+\.png$ /apple-touch-icon.png [L]

# These rules should only apply to PHP scripts, so most of my rules would go here
# Does it match implied directories? Like example.com/blah/ instead of example.com/blah/index.php
<FilesMatch "\.php$">
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} !^/(?:includes|members) [NC]
RewriteRule (.*) /blah/$1 [E=FOO:bar,L]

RewriteCond %{HTTP_HOST} whatever\.com [NC]
RewriteCond %{REQUEST_URI} !^/(?:includes|members) [NC]
RewriteRule (.*) /something/$1 [E=FOO:else,L]
</FilesMatch>

# would this still show a 404 for failed images?
ErrorDocument 404 /404.php

lucy24

10:18 pm on Apr 30, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<tangent>
The pattern in
RewriteRule ^apple-touch-icon.+\.png$ /apple-touch-icon.png

can be more efficiently expressed as
^apple-touch-icon-

without closing anchor, so the server doesn't have to go all the way to the end and then backtrack. Since you’re not capturing, all you need to say is “apple-touch-icon-andmorestuff”. It’s always a hyphen. (I found one exception in logs, but it looks like a confused robot.)
</tangent>

mod_rewrite can be used inside <Files> envelopes--I've done it in the past--but be warned that Apache doesn’t like it and therefore doesn’t document it.

Anything inside a <Files> envelope will execute after anything not in a <Files> envelope. And you have to say “RewriteEngine on” over again. More importantly, the capture (.*) will probably not work as intended, since it will capture the whole physical filepath, not just the part after the / site root.

In this recurring RewriteCond--where I assume there’s a separate RewriteRule for each of the many hostnames--
RewriteCond %{REQUEST_URI} !^/(?:includes|members) [NC]
--you can instead make a preliminary rule, right at the beginning of the <Files> envelope, that says
RewriteRule /(includes|members)/ - [L]
and then you don't need a Condition for all the following rules.

One year seems a perilously long caching time for css, though perfectly reasonable for images. Don’t you ever tweak your stylesheets?

# Does it match implied directories? Like example.com/blah/ instead of example.com/blah/index.php
I’m not sure how the question applies to the cited rules. /blah/ is a directory; /index.php is a file.

I don't want to add 4kb+ to the server configuration if it's going to run unnecessarily on every HTTP request
I think this takes us back to the config-vs-htaccess question. The server reads the config file at startup (or at config reload if that's an option you use), compiles any regular expressions, and then effectively memorizes the whole thing until further notice. The htaccess file is read and compiled over again on every request. So the question is whether the server actually takes action every time, or if the action is only triggered by page requests. To me it seems as if it would make more sense to leave it in a php script rather than throw it into config.

csdude55

11:34 pm on Apr 30, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<tangent>...</tangent>

Awesome, thanks for the heads up on that!

mod_rewrite can be used inside <Files> envelopes--I've done it in the past--but be warned that Apache doesn’t like it and therefore doesn’t document it.

In my preliminary test I found that I worked, but I couldn't find documentation on it... so that explains that! LOL That's why I got nervous, though, for fear that Apache might stop supporting it and all of my work would have to be undone.

More importantly, the capture (.*) will probably not work as intended, since it will capture the whole physical filepath, not just the part after the / site root.

Oh... well, that kinda throws a wrench in the monkey works :-( So you're saying that:

<FilesMatch "\.php$">
RewriteEngine on

# this: https://www.example.com/whatever
RewriteRule (.*) /blah/$1 [E=FOO:bar,L]
</FilesMatch>

# would rewrite to:
https://www.example.com/blah/home/example/public_html/whatever


If that's correct, could I simply modify to this?

<FilesMatch "\.php$">
RewriteEngine on

RewriteRule /home/example/public_html/(.*) /blah/$1 [E=FOO:bar,L]
</FilesMatch>


One year seems a perilously long caching time for css, though perfectly reasonable for images. Don’t you ever tweak your stylesheets?

Not really... on the live site, my last modification was last October, but I honestly don't know what I changed. I think it was just when I changed Google ads from fixed size to responsive. Other than that, though, I don't really mess with it once it's working.

Any caching seems like it would be problematic, though... even if it's only going to cache for a week then I could change something today and worry about it not being right until next week. So if I did change a style then I would probably just change the header file to use styles.css?z=1 or something like that.

How long do you have yours cached?

I’m not sure how the question applies to the cited rules. /blah/ is a directory; /index.php is a file.

This was actually an important question for me... if the URL is example.com/whatever, DirectoryIndex is going to make it load example.com/whatever/index.php . So am I correct that <FilesMatch "\.php$"> would match for both the explicit AND implicit .php?

I think this takes us back to the config-vs-htaccess question. The server reads the config file at startup (or at config reload if that's an option you use), compiles any regular expressions, and then effectively memorizes the whole thing until further notice. The htaccess file is read and compiled over again on every request. So the question is whether the server actually takes action every time, or if the action is only triggered by page requests.

You are correct, of course... I'm putting it in the .htaccess while building, but before going live everything'll end up in the config file. I'm also running with PHP 5 right now, but I'll update to PHP 7 before I go live. That makes it harder for me to test performance on anything with any real certainty :-(

To me it seems as if it would make more sense to leave it in a php script rather than throw it into config.

Do you mind elaborating on why you think it makes more sense to leave it in PHP? Based on what you said, I thought that it would be faster to load it 1 time in the config rather than over and over on each page request.

lucy24

2:44 am on May 1, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So am I correct that <FilesMatch "\.php$"> would match for both the explicit AND implicit .php?
:: business with test site ::

Urk, I remembered wrong. <Files> only applies to the visible URL--including requests that would normally be redirected. So if you have a
<Files "index.html">
any RewriteRules inside this envelope will be activated by an explicit request for /dir/index.html (for example by typing it in, or selecting the file in your FTP program and saying Web View or equivalent), but not by a request for /dir/ leading to an internal request for /dir/index.html.

Reminder: In the case of a request for /dir/subdir where "subdir" is real, physical directory, mod_dir takes two separate actions: first an external 301 redirect to /dir/subdir/ and then, when this new request comes in, an internal rewrite-in-all-but-name to /dir/subdir/index.php

How long do you have yours cached?
:: detour to refresh memory ::

Oh, guess I really don't say much.
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 7 days"
and for the one site that has .wav files, those are 3 months, while piwik.php is set to 5 minutes. (This may be unnecessary, since each request comes with a vast query string which would make it a different URL anyway, unless it's a scriptless visitor.) On my test site, everything is set to "access"--i.e. no caching at all--because it's a test site.

I'm inclined to suspect--but don't know if documentation exists--that if you set an extremely long caching time, the browser will simply ignore it and follow its own judgement.

RewriteRule /home/example/public_html/(.*) /blah/$1 [E=FOO:bar,L]
:: further business with test site ::

Yup, exactly. I remembered this part accurately because back when I had a <FilesMatch> envelope to deal with image files, I had to leave off the ^ opening anchor in patterns, since it would no longer be the opening.

The important question (which I've put off)
I thought that it would be faster to load it 1 time in the config rather than over and over on each page request.
It is possible I’ve misunderstood the situation. Is the variable/constant/whatever supposed to be set once and for all for the entire server to last until further notice--or is it set anew for each page request? Isn't the php script already running on every page request? 4k really doesn't seem like colossal overhead, considering all the assorted refuse that accompanies a typical page.

I've also got a hunch that it isn’t reading the script that’s a drain on server resources, it’s acting on it--and that part would be the same, no matter where the script is located. So it may come down to--World’s Most Unhelpful Answer--our old friend, Personal Coding Style.

csdude55

3:59 am on May 1, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It is possible I’ve misunderstood the situation. Is the variable/constant/whatever supposed to be set once and for all for the entire server to last until further notice--or is it set anew for each page request? Isn't the php script already running on every page request? 4k really doesn't seem like colossal overhead, considering all the assorted refuse that accompanies a typical page.

I would be tickled if the variable would be set once and for all; this data will likely never change. The variables I'm setting are the Analytics ID, the "type" of site it represents, text for the logo, text for a background section, and a few other domain-specific details; eg:

$analytics = 'UA-12345-67';
$siteType = 'forum';
$siteName = '<H1>Foo</H1><H2>Bar</H2>';
$bgText = 'Message Board';


I have roughly 100 domains, so at the moment I have it in a switch-case. Which is relatively fast to process, but since I already have the RewriteCond for each domain in the .htaccess anyway, I don't think that it would be any slower to add [E=ANALYTICS:UA-12345-67].

But I'm also comparing it to data saved in a session variable, so that switch is (in theory) only read on the first pageload for the session. After that, it's just 4kb of data being downloaded for nothing.

I guess I could realistically set a [CO] cookie in .htaccess instead of an [E] variable, but I'm not sure how to READ the cookie and make htaccess skip ahead if it exists...

You're right that 4kb isn't exactly huge (especially after compression), but I'm just shaving time wherever I can in an attempt to speed up load time, which (again, in theory) long-term results in more pages per session. If this would save 200ms on the average page load, it could potentially be worth a few hundred dollars each month... so it doesn't hurt to do what I can while I'm still dealing with writer's block :-/

lucy24

4:15 pm on May 1, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



but I'm not sure how to READ the cookie and make htaccess skip ahead if it exists...
It's done in a RewriteCond.

Example taken from the ONLY place on any site where I currently check cookies. The function of the rule is to redirect smartphone requests for a handful of pages that I don’t think will work satisfactorily on such small devices, unless the user absolutely insists. (Mainly because these pages have an enormous number of supporting files* that I don’t want to send out if I don’t have to.)
RewriteCond %{HTTP_USER_AGENT} (Android|iPhone|iPod)
RewriteCond %{HTTP_COOKIE} !phonegame
RewriteCond %{HTTP_REFERER} !phone\.html
RewriteRule ^games/(tower|palace|canal|color)/?$ https://www.example.com/games/phone.html [R=302,CO=phonegame:1:.example.com:525600,L]
Now, I think what this actually means is that it checks whether the text string “phonegame” occurs anywhere in the “Cookie” header field, and that if I were testing for some specific value, I’d have to say
cookiename=blahblah

The key part is to constrain the rule to page requests. The pattern will of course depend on your site’s URL structure. In my quoted example I made the final / optional to cover type-ins, so nobody gets redirected twice.

If you need to skip a whole bunch of rules, it may be better to check for the cookie and then put in the [S] flag--very, very carefully since you have to make sure you’re skipping the right number of rules. To quote The Docs regarding [S] (while omitting their RegEx patterns, which set my teeth on edge):
This technique is useful because a RewriteCond only applies to the RewriteRule immediately following it. Thus, if you want to make a RewriteCond apply to several RewriteRules, one possible technique is to negate those conditions and add a RewriteRule with a [Skip] flag. You can use this to make pseudo if-then-else constructs:


* Most of the time when we think about blocking or redirecting, it’s about robots. But sometimes instead it’s the human visits that may be a waste of time. For the same reason, I 302 redirect certain requests from South Asia.

csdude55

8:59 pm on May 1, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you need to skip a whole bunch of rules, it may be better to check for the cookie and then put in the [S] flag--very, very carefully since you have to make sure you’re skipping the right number of rules.

I absolutely hate the [S] flag, too... it makes future edits incredibly easy to mess up! That's why I was liking the <FilesMatch ...> option, it was grouping everything together quite nicely.

I might try something like this:

<FilesMatch "\.php$">
RewriteEngine on

RewriteCond %{HTTP_COOKIE} foo=\w
RewriteRule ^ - [L]

# old, uses env
# RewriteRule (?:/home/example/public_html/)?(.*) /blah/$1 [E=FOO:bar,L]

# new, use cookie instead of env
RewriteRule (?:/home/example/public_html/)?(.*) /blah/$1 [CO=foo:bar:.example.com:86400,L]
</FilesMatch>

Downside there is that if the user doesn't have cookies enabled (or if some POS security software is blocking cookies) then it would miss important variables. I'm not sure if that would include important search engine bots, but... maybe. So I'd probably have to double-down:

// in the htaccess
RewriteRule (?:/home/example/public_html/)?(.*) /blah/$1 [E=FOO:bar,CO=foo:bar:.example.com:86400,L]

// in variables.php that's included on every PHP page
$foo = isset($_COOKIE['foo']) ? $_COOKIE['foo'] : $_SERVER['FOO'];

I got about halfway finished with setting the [E] variables yesterday, so I think I'm gonna set it up all 3 ways (using switch-case and sessions, versus setting [E] in htaccess, versus setting a cookie AND [E] in htaccess) and then do a speed test on all three. But it'll be on a live server so I'm not sure how reliable the speed test will be, unless there's a BIG speed difference.

lucy24

11:58 pm on May 1, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure if that would include important search engine bots, but... maybe.
Definitely, I should think, since I don’t remember any robot ever coming in with a cookie. A legitimate cookie, that is; malign robots occasionally send bogus cookies that have nothing to do with my site. (What on earth, for example, is humans_21909=1 ? It seems to have been quite popular for a while.) Empty Cookie: headers are also surprisingly popular, especially followed by “Referer: google.com” [sic].

So it would require an [OR]-delimited set of conditions: one for the cookie, another to exclude all authorized robots by name. But I suppose you’ve already set up some way of dealing with cookieless visitors, whether they’re legitimate robots or careful humans.

RewriteRule (?:/home/example/public_html/)?(.*) /blah/$1 [E=FOO:bar,CO=foo:bar:.example.com:86400,L]
Don’t you need an opening anchor-and-slash for the pattern? For efficiency if nothing else. And is that really a ? at the end of the lookahead? There’s not much sense in declaring a lookahead and then turning around and making it optional. I checked in the nearest text editor to see if it was even syntactically legal. Surprisingly, it raised no objection.

Edit: If you do take the <Files> route, be sure to include an appropriate inherit directive, like
RewriteOptions Inherit
if you haven’t already set it in the config file as a whole (InheritDown and similar). Anything inside a <Files> envelope essentially behaves the same as a set of RewriteRules in a subsequent directory: the old ones are abandoned unless you’ve explicitly told the server to retain them. Apache 2.4 has a lot more options than 2.2, so spend some time deciding which one is most appropriate.

csdude55

4:44 am on May 3, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I understand that you can't use an environment variable in the match part of a rule, right? So this doesn't work:

<FilesMatch "\.php$">
RewriteEngine on

RewriteRule ^%{DOCUMENT_ROOT}/(.*) /blah/$1 [L]
</FilesMatch>

Is there any way around that? I ask because I'm working in a subdomain for production, and when I go live it'll just be more down time for me to remember to change the root path on all of the rules. It'd be MUCH easier if I could use DOCUMENT_ROOT!

lucy24

5:10 am on May 3, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^%{DOCUMENT_ROOT}/(.*) /blah/$1 [L]
Ooh, interesting. Normally that would be impossible because in a directory section the DOCUMENT_ROOT simply isn’t part of the URLpath, but if you’re in a <Files> envelope ... nope, still wouldn’t work, this time because the physical filepath doesn’t contain the actual DOCUMENT_ROOT but just some variant thereof, depending on directory structure on your server.

But here I don’t understand what the DOCUMENT_ROOT is doing at all, since it isn’t part of the capture. Or is the point that you need to exclude it while keeping everything else? Then just put whatever the actual filepath is, like
RewriteRule ^/home/[^/]+/public_html/(.*) /blah/$1 [L]
where the [^/]+ part is your various domain names like example.com, example.org, example.xxx and so on. I think it starts with a / once you're in FilesMatch.

I'm going to try this on my test site to make sure it rewrites as intended (obviously not an issue with external redirects, which is what I'd normally use for testing). But not tonight.

csdude55

7:21 am on May 3, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The issue is that my subdomain is set up at /home/example/ww2.example.com (which matches DOCUMENT_ROOT). When I go live, it'll move to /home/example/public_html

I can probably get away with ^/home/example/[^/]+/(.*), though, that's a good common-sense idea :-) I got so caught up with using DOCUMENT_ROOT that I think I overlooked the obvious! LOL

lucy24

5:17 pm on May 3, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I’ve just checked the rewrite. I wanted to make sure that, in a <Files> envelope, a target involving /blahblah still interprets / as the document root, even though the pattern no longer begins with the root.

Along the way, I confirmed that once you’re inside a <Files> envelope, the pattern starts with a / slash, exactly as if the rule were lying loose in config.

As long as all your various (sub)domains are at the same directory level
/home/example/sub1/
/home/example/sub2/
/home/otherside/moresub/
this should work in <Files>. I used [^/] as the safest way to say “exactly one directory here”. (For URLpaths within a site I would instead have said \w+ but here you need to allow for the . dot.)

It sounds as if you’re just about there :)

csdude55

8:17 pm on May 8, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I wanted to give you an update on speed tests...

Even though my sandbox is a subdomain that no one else knows about, it's on a live server. So this isn't a perfect test, it's subject to traffic changes between tests. But I did a test yesterday at 10pm, another at 2am this morning, and a 3rd just now (at 3pm)... all times that traffic seemed relatively low.

In all 3 tests, moving variables to .htaccess was marginally faster than setting them via PHP.

I'm using this page to do a load time test:

[webpagetest.org...]

That's different from a benchmark test of 10000 iterations, of course, but in this case I'm testing against a full variables.php script and want to compare how quickly it loads AND utilizes the variables.

My new htaccess uses this to set all of the [E] variables:

<FilesMatch "\.php$">
RewriteRule ^ - [E=FOO:bar]
</FilesMatch>


The original htaccess file was 8,791 bytes, the new one is 13,940 bytes.

I listed these separate from the RewriteRules that I had set up before. I originally thought I could do them all together, but then I realized that I had RewriteCond in my earlier rules that would make the rule not match when I wanted to set a variable. So I just did them all separate, and only set them when the page requested is PHP.

In the original PHP script I used switch-case, like:

// I force www or ww2 in htaccess
list($protocol, $domain, $ext) = explode('.', $_SERVER['HTTP_HOST']);

switch ($domain) {
case 'example':
$varA = 'a';
$varB = 'b';
$varC = 'c';
break;

case 'foo':
$varA = 'd';
$varB = 'e';
$varC = 'f';
break;

// and so on, for all of my parked domains


In this variation, I changed it to:

// in .htaccess
<FilesMatch "\.php$">
RewriteCond %{HTTP_HOST} ^(?:www|ww2)\.example\. [NC]
RewriteRule ^ - [E=VARA:a,VARB:b,VARC:c,L]

RewriteCond %{HTTP_HOST} ^(?:www|ww2)\.foo\. [NC]
RewriteRule ^ - [E=VARA:d,VARB:e,VARC:f,L]
</FilesMatch>

// PHP
$varA = $_SERVER['VARA'];
$varB = $_SERVER['VARB'];
$varC = $_SERVER['VARC'];

// I might change the PHP to:
// foreach ($_SERVER as $key => $val)
// $$key = $val;


For my test, I used example.com because it's the first domain in both the switch-case and in the [E], so in theory the others would be ignored.

Also, my original script uses SESSION variables, so they're (in theory) only set once, while the new modification using [E] sets them anew each time. I might change the new htaccess to use cookies and test again.

The average load time:

FIRST RUN
original script: 3.829s
new script, using [E]: 3.014s

SECOND RUN
original script: 4.472s
new script, using [E]: 2.842

THIRD RUN
original script: 2.810
new script, using [E]: 2.755


In every test, using [E] instead of switch-case was faster. The second run was slower for the original script in every test and I'm not sure why, but even if I ignore that run as an anomaly then the first and third run were still considerably faster with using [E].

lucy24

9:39 pm on May 8, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Whee!

As long as we’re here ... Something that I should have remembered much sooner about case switching: Since it’s your own server, you can also flatten casing in URLs via a RewriteMap (er... it was you, wasn’t it, whose father has a hard-coded Caps Lock?):
http://httpd.apache.org/docs/2.4/rewrite/rewritemap.html#int
(where “int” means “internal”, referring to four built-in maps) as in
RewriteMap lc int:tolower

RewriteRule (.+) ${lc:$1} [R=301,L]
This may or may not be useful in your situation, but it’s an option to keep in mind.

The RewriteMap directive cannot be used in <Directory> sections or htaccess. That is: you can use a map in htaccess, but only if it has been declared in config. And no, I have no idea why the examples in the docs are so littered with quotation marks; I really doubt they are required. (Unlike most things, I can’t scurry over to my test site and try it out :()

csdude55

3:54 am on May 10, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Kewl :-) And you're right, my dad does keep his caps-lock on, but after discovering that I realized that I had a lot of 404s for the same thing, so I think that a lot of older people to do that.

I see that I have to put part of it in httpd.conf, which isn't a big deal, but I think I'll play with that when I get to the new server or I'll forget what I did! LOL

You've led me to a whole new thing, though... time for a new thread

csdude55

9:57 pm on May 12, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



FIRST RUN
original script: 3.829s
new script, using [E]: 3.014s

SECOND RUN
original script: 4.472s
new script, using [E]: 2.842

THIRD RUN
original script: 2.810
new script, using [E]: 2.755


Further update... remember that I use require_once 'variables.php'; on every script of my site. This PHP script originally had a MySQL query for a table with 100 rows, where it looked for the domain name being accessed to store variables. It then pushed those variables to a SESSION, so (in theory) it only did the query on the first access.

For this third test, I moved all permanent variables, including the results of the entire MySQL table, to .htaccess:

<FilesMatch "\.php$">
RewriteCond %{HTTP_HOST} ^(?:www|ww2)\.([^.]+)\. [NC]
RewriteRule ^ - [E=domain:%1]

RewriteCond %{ENV:domain} ^example$ [NC]
RewriteRule ^ - [E=foo:bar,E=lorem:ipsum]
</FilesMatch>

// PHP
foreach ($_SERVER as $key => $val)
$$key = $val;


I was also able to stop using SESSION. In the end, my .htaccess went from 7.2kb to 29.1kb (increase of 21.9kb), and my variables.php went from 21.5kb to 12.3kb (decrease of 9.2kb).

Now, the load times are:

FIRST RUN
original script: 3.829s
new script, using [E]: 2.726s

SECOND RUN
original script: 4.472s
new script, using [E]: 2.651

THIRD RUN
original script: 2.810
new script, using [E]: 2.185


You can see that using [E] variables has decreased the load time by over 1 second on the initial load, which should result in more pages per session. And I suspect that there will be slightly less strain on the server with 1 less MySQL query on every page, but I'm not sure that I'll be able to measure that.

lucy24

10:56 pm on May 12, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



decreased the load time by over 1 second
I was looking at proportions: a savings of anywhere from 20% to 40%. Very striking.

In the long term, the increase in htaccess size will make no difference whatsoever, since all this stuff has to be read somewhere. And if I remember rightly,* you’re eventually moving it all to config where it only has to be read once, at server startup.

:: idly wondering how truly vast a config file would have to be before its size starts creating memory problems for the server! ::


* My brain would not make a good Apache server, what with the requirement to remember more than one thing for more than one minute.

csdude55

12:07 am on May 13, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



And if I remember rightly,* you’re eventually moving it all to config where it only has to be read once, at server startup.

You are correct, once I'm ready to go live I'll provision a new server. But it'll have more RAM, HTTP/2, and will be using PHP 7 (instead of 5.x that I have now), so there would be more variables that would affect the test.

Before I move, though, I might spend some time and move everything to my current server's config file, just for testing.

But yeah, a 20-40% savings got me pretty tickled :-) It took a few weeks to get it all right, but I think it's worth the effort.