htaccess performance issues vs restarting the server
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, httpd.conf, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem : I usually use the server config file for settings that I would like to apply to my applications (at least in the development environment), and constantly have to re-start the server.
I know that I cannot keep re-starting the server every time during production; my choice would have to be .htaccess files.
My question is this: how much performance issue does using htaccess files cause? I understand that it depends on how many folders the request has to traverse to obtain the required file; so here's an example:
If the request path is host/folder1/folder2/folder3/folder4/folder5/file_requested, and the htaccess is placed in the root folder, are we talking about a significantly, measurable performance issue, or something that can be ignored? I wouldn't want to restart the server every time I need changes to an application's configuration.
Thanks.
Well, as mentioned by @Book of Zeus, this depends on how affecting are your rules.
.htaccess works with a hunting process, this means... suppose you have a file being accessed at
/var/www/foo/bar/baz/dir1/dir2/file.ext
Apache will first parse and identify if file or directory exists. Then it will check if there is any .htaccess file inside /var/www/foo/bar/baz/dir1/dir2/. If it matches, it processes and we are fine, if not, it will check the parent directory (/var/www/foo/bar/baz/dir1/) for a .htaccess and, if it encounters one, process the matching rules. If not, it proceeds to the parent and check... you got the pattern... until reach the root folder.
Summarizing, the closer to the target file the .htaccess is, higher the precedence in the hunting process.
In any case, my final suggestion is test it. Make some changes in the Apache configuration file, restart, and benchark it. Then rollback your changes a put them into a .htaccess files and run the same test. Check for response times and memory usage. Try to replicate your production load. This ca be your final silver bullet deciding which method you should adopt.
If this indicates you that changing Apache config and restart is really better, try to implement changes of the day all at once, in a nightly job run to minimize the prod impact.
PS: Apache comes with a program named "ab" - apache bench - in its default installation. You can use it to make your tests.
Comments
Post a Comment