In the past week I've dealt with some servers that were seeing some rather heavy load, with more traffic on the way. I noticed that the servers had AllowOverride All in their httpd.conf files, which immediately struck me as a problem. While .htaccess files can be quite handy during development (AllowOverride instructs Apache to process those .htaccess files), they're also quite horrible in production due to the performance hits involved in using them. Since the files allow configuration to be changed on the fly, they need to be read on every request. This requires a lot of unnecessary stat calls with each and every request.
I approached the development team requesting permission to turn the option off, in order to squeeze some extra performance out of each server. Rather than the happy smiles and agreement I expected, I was instead met with nervousness and uncertainty. Since the front end team uses them constantly, there was concerns that the change over from .htaccess to httpd.conf would consume a lot of time, and would be very difficult to maintain moving forward.
In order to allay their fears I created a .htaccess to httpd.conf script with the help of my friend Rich Bowen. It's designed to be executed from the command line from a sufficiently permissioned user from within the document root. It recursively scans all sub directories looking for .htaccess files, reads them in, and spits it all back out. There's a bit of intelligence involved in order to present the contents of .htaccess files with the least depth first (this way overriding works correctly), and warnings are generated if the RewiteBase instruction is encountered as it may require extra tweaking. Other than that I generally just pipe the output to htaccess.conf, then include that file from my basic configuration file. By re-running this script (and, of course, gracefully restating the server after checking to make sure all the conf files parse) as part of my normal sync process I get all the flexibility of .htaccess files, without the performance hit.
The script requires PHP 5, probably 5.1+ would be safest.
No warranties, test extensively. In terms of field testing (against my rather limited set of .htaccess files) it's been running on a site +10M uniques/day, using roughly 40 .htaccess files. I'd love to hear from you if you end up using it.
Source:.htaccess to httpd.conf converter, and again with thanks to Rich Bowen.
I approached the development team requesting permission to turn the option off, in order to squeeze some extra performance out of each server. Rather than the happy smiles and agreement I expected, I was instead met with nervousness and uncertainty. Since the front end team uses them constantly, there was concerns that the change over from .htaccess to httpd.conf would consume a lot of time, and would be very difficult to maintain moving forward.
In order to allay their fears I created a .htaccess to httpd.conf script with the help of my friend Rich Bowen. It's designed to be executed from the command line from a sufficiently permissioned user from within the document root. It recursively scans all sub directories looking for .htaccess files, reads them in, and spits it all back out. There's a bit of intelligence involved in order to present the contents of .htaccess files with the least depth first (this way overriding works correctly), and warnings are generated if the RewiteBase instruction is encountered as it may require extra tweaking. Other than that I generally just pipe the output to htaccess.conf, then include that file from my basic configuration file. By re-running this script (and, of course, gracefully restating the server after checking to make sure all the conf files parse) as part of my normal sync process I get all the flexibility of .htaccess files, without the performance hit.
The script requires PHP 5, probably 5.1+ would be safest.
No warranties, test extensively. In terms of field testing (against my rather limited set of .htaccess files) it's been running on a site +10M uniques/day, using roughly 40 .htaccess files. I'd love to hear from you if you end up using it.
Source:.htaccess to httpd.conf converter, and again with thanks to Rich Bowen.
Comments »
This is awesome, thanks for the post. I've secretly been copying .htaccess from svn and adding to my vhost confs, letting the developers think they have access to .htaccess. I'm surprised as to how few developers see or care about the adverse effect of using .htaccess in their production vhosts.
Can't wait to try this script out.
Can't wait to try this script out.
Could you please describe how well this change affected the load? Thanks
Well, it can only do good things, how good those things are depends on a lot of stuff.
- The more heavily loaded your server is, the more this will help.
- IO bound systems will see more than others
- The more nested your directory structure for file and URLs, the more .htaccess files apache will look for, so the more it will help.
So no hard and fast numbers, your mileage will vary.
- The more heavily loaded your server is, the more this will help.
- IO bound systems will see more than others
- The more nested your directory structure for file and URLs, the more .htaccess files apache will look for, so the more it will help.
So no hard and fast numbers, your mileage will vary.
What a great script to share, I am sure this will come in very useful.
Do you have any kind of information about what kind of improvement you saw after making this change?
Do you have any kind of information about what kind of improvement you saw after making this change?
Great information. Thank you Paul.
Also some benchmarks would be so interesting
Also some benchmarks would be so interesting
Please correct me if I am wrong but this bit of code(line:23-28) serves no purpose that I can notice.
[code]
//Merge base set of filters with any from the command line
if(count($argv) > 0)
{
unset($argv[0]);
$filters = array_merge($filters, $argv);
}
[/code]
It will only kick out a PHP Notice of an undefined variable. Unless this is a part of PHP I am not familiar with I am assuming the code above is useless.
[code]
//Merge base set of filters with any from the command line
if(count($argv) > 0)
{
unset($argv[0]);
$filters = array_merge($filters, $argv);
}
[/code]
It will only kick out a PHP Notice of an undefined variable. Unless this is a part of PHP I am not familiar with I am assuming the code above is useless.
Please ignore my previous post, I didn't read the comments and now I just look stupid.
Thanks for the script! Very useful.
Thanks for the script! Very useful.
Hi all,
I am a newbie in php
I want to know how to change the url address for remote access.
I don't know how to use .htaccess and httpd.conf
I found many topics related these but still can't.
e.g http://192.100.0.23/myfolder/login.php
to
http://192.100.0.23/newname
waiting for reply.....
I am a newbie in php
I want to know how to change the url address for remote access.
I don't know how to use .htaccess and httpd.conf
I found many topics related these but still can't.
e.g http://192.100.0.23/myfolder/login.php
to
http://192.100.0.23/newname
waiting for reply.....
Tracked: Nov 20, 22:57