Forum Moderators: phranque

Message Too Old, No Replies

Accessing Apache Environment Variables for Arbitrary Directory

Whether or not apache's internal cache of env vars (assuming it exists) is

         

clancyhood

8:56 pm on Jun 2, 2011 (gmt 0)

10+ Year Member



Hi

I've been googling this, but the search terms are too common and return a lot of irrelevant results. Hopefully someone has experience of something like this:

I'd like to be able to determine what apache environment variables are set for a given directory - NOT the parent directory of the running script (easily done), but any other directory.

Presumably, apache determines the environment variables (and all other options) set in .htaccess files by traversing upward, e.g. if I run a script in /var/www/clancy then apache first looks in /var, then /var/www, and finally /var/www/clancy for .htaccess files. Each is processed in this order, so that if /var/www/.htaccess looked like this:


SetEnv foo bar


and /var/www/clancy/.htaccess looked like this:


SetEnv foo baz


then running the following in /var/www/clancy/foo.php

<?php echo getenv('foo'); ?>


... yields "baz".

Now if I were writing an application that served this purpose, then I would probably cache these values in a small database and stat .htaccess files for modification times, rather than parsing an indeterminate number of .htaccess files on every single hit on a server asset. I could in fact do exactly this (and am possibly about to), but before I reinvent the wheel, does does anyone know of a way in which I can make use of apache's inherent ability to collate this data?

Hope this is clear. Thankyou very much for any help

Clancy

clancyhood

9:53 pm on Jun 2, 2011 (gmt 0)

10+ Year Member



At the risk of answering my own question and stymying the upcoming interesting conversation...

Given that htaccess options can be dependent on input (e.g. if they are under a directive such as FilesMatch) then it is impossible to reliably determine what environment variables may be set for a given directory without synthesizing (knowing in advance) the domain name, headers sent, and any other variable input that may determine options set. Silly me.

I suppose what I might need is a handler to process my own requests (good tutorial at [threebit.net...] ) and dump envvars to stdout, though this still of course leaves some above mentioned angles uncovered.

Sorry for the apparently daft question. Thanks all :)