homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Whitespace and comments in htaccess
Does it affect performance?
migthegreek




msg:4191359
 10:11 am on Aug 24, 2010 (gmt 0)

I was just wondering if there is any harm in adding heavy blocks of comments or extra line breaks in an htaccess file to make it more readable.

I'm going to be sharing an htaccess file with a couple of people who need to be able to configure it quickly and easily, and it would be nice to be able to point them to the sections they need to edit.

Something like this:


#################################
# SECTION 1
#################################

code
code

#################################
# SECTION 2
#################################

code
code
code

...etc. Will the extra bytes add any overhead or deminish performance of the site?

 

jdMorgan




msg:4191428
 2:37 pm on Aug 24, 2010 (gmt 0)

Every line in the file gets parsed. If it starts with a "#", then the parser stops trying to interpret the line as code, and simply begins looking for the end-of-line.

So yes, adding comment lines slows things down a little, but not as much as adding the same number of 'real' directives would.

I'd suggest that you do away with the "#####################" container lines, and simply use "#" for individual line comments, "##" for individual rule comments, "###" for subsections, and "####" for main sections. Or -as you did- use all-capital letters for the main sections, and Title-Casing for subsections, Initial-uppercase for individual rules, and all-lowercase for individual line comments. Or perhaps some combination of the two -- As long as there is a systematic method, you're good.

What really wastes time in WordPress installs is the poorly-coded rewriterules that they supply. They essentially do at least two, but possibly up to three filesystem accesses for every single HTTP request that comes to your server. This is because they used unqualified "exists" checks in their code, without thinking through what those checks actually involve doing on the server: Each results in a call to the operating system to invoke the filesystem handler to determine whether a file or directory exists. If the current state of the filesystem is not cached in memeory or is stale, this results in actually reading the physical disk.

So best case, each of these "exists" checks results in executing hundreds or thousands of lines of code in the OS and filesystem handler, and worst-case, it results in executing even more lines of code, plus accessing and reading the physical disk. This is likely the cause of many premature disk failures and apparently-required performance-related server upgrades. I look at that code and say, "What were they thinking?!?"

I have posted modified WordPress .htaccess code here in many threads here that addresses the most egregious problems with the code, and I recommend those modifications to you. On a busy site on shared hosting, the mods will likely make a *very noticeable* difference in your site's page-loading time.

The modification consists of skipping the file- and directory-exists checks for (previously-rewritten) requests the WP script filepath itself, and for included-object requests that Wordpress cannot generate content for, even if the requested object does not exist.

So, in simple terms, requests for WP's index.php file and for image, css, and JavaScript files by-pass the 'exists' checks, eliminating the majority of "wasted" exists-checks. The 'list' of files and filetypes can be expanded to include multimedia files and document files as well, but excluding just the basic set described here will make the most difference.

The mod also gets rid of the <IfModule> container that they insist on using, whose only real effect is to make their code fail silently on servers where mod_rewrite is not available -- not exactly what a Webmaster debugging a major problem would want, and I have no idea why they insist on including it.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved