adephue Posted January 5, 2008 Posted January 5, 2008 (edited) I am a web developer by trade and I am looking to streamline my local developing experience in the following way. As a precursor to my question, I have Apache and MySQL running locally on my PC. Currently, if I pull down a new client's website for development (let's say www.somedomain.com); I create an Apache virtualhost for dev.somedomain.com AND a hosts file entry to resolve dev.somedomain.com to a local IP address. Frequently I find hard-coded absolute URL's which requires me to find/replace, make site changes, find replace again, then upload. What I would like to do is develop locally as www.somedomain.com, run a script to change my PC's settings, upload files, then check on the WWW to make sure everything is ok. Currently I have a script that 1) switches the default hosts file with the one I made with my site entries (or vice versa) -and- 2) flushes the local DNS cache. So, I boot up the PC and my hosts file is default. I type www.somedomain.com into my browser and online content from the web is displayed. Now here's the problem. I run my switch script which swaps hosts files to the one having an entry for www.somedomain.com and flushes the local DNS cache. If I ping www.somedomain.com it resolves locally. if I ipconfig /displaydns it is listed as having a local IP address... problem is, it takes almost 5 minutes for any browser to start displaying local content. I have tried clearing browser cache. I have tried hard refresh. I have tried stopping/starting Apache. I have tried stopping/starting local DNS service. I have tried killing local DNS service altogether. I have tried altering the registry to locally cache DNS entries for only a few seconds. If I wait a few minutes, www.somedomain.com starts displaying locally served content like it should. SO... I run my switch script again and the reverse happens. Ping and displaydns show outside-world IP's but the browsers take about 5 minutes to reflect changes. Bottom line ::: I hope to find a way for the change to be instantaneous in my web browsers. Any ideas? Edited January 5, 2008 by adephue Quote
pagoda Posted January 5, 2008 Posted January 5, 2008 Greetings adephue, Although you did not specifically use the word "Windows" to describe your PC, I am going to assume that was/is your intent... Even if this not the case, these same concepts work on *nix machine except for the files /etc/hosts. What I do (I too am a web and graphic design - meaning fundamentally marketing and advertising) is to do one of the following depending on the mood I am in and the complexity of the site: 1) The Simple Solution: Look in D:\Windows\system32\drivers\etc\hosts. If you are familiar with Linux or other *nixes then this will be a cake walk. Simply add the appropriate entry into this file. It is ever so slightly different than the *nix world in that the entries can only have one domain attached to them. However, you can use multiple domains on separate lines. Using your example, this might look like: 205.205.205.205 somedomain.com 205.205.205.205 www.somedomain.com 205.205.205.205 ftp.somedomain.com etc... Where 205.205.205.205 is a your live domain name (available using WHOIS). Now, to work on your local machine, regardless of whether it is Windows Box, Linux Box or Mac (these all follow the same conventions per ICANN rules) you would most likely set this up as follows: A) Remove (comment out with # the entries above) and edit the same ../etc/hosts file and add: 192.168.0.10 somedomain.com 192.168.0.10 www.somedomain.com 192.168.0.10 ftp.somedomain.com etc. This preassumes that you have the correct software set up to use ftp (if you in fact want to, although there is no need when editing locally, etc.) 2) The second method is to create a dummy directory on your life server at TCH. This may be something like www.somedomain.com/devel and then use relative links instead of absolute links (which is, in general, good practice anyway). This bypasses any quirks that may occur while trying to develop on a Windows machine using Apache, MySQL and PHP. I too use Apache, MySQL, PHP, Perl, Tcl/Tk, Python and Ruby on my Windows XP machine and their are subtle, but significant differences when pushing the sites to the the TCH Linux machines. Bottom line - if you are comfortable learning these subtleties, then I recommend using the Windows platform to develop on since it integrates nicely with Dreamweaver and Komodo, two very powerful tools. 3) Finally, there is an even more elegant solution that you may wish to try: I have several Linux systems at home (my business is home based) - one of these is set up to almost identically mirror the environment on the TCH machines. Thus, you have the option of developing in an environment like this and then pushing the content to TCH. I hope this helps. Cheers, Patrick Quote
adephue Posted January 5, 2008 Author Posted January 5, 2008 Thanks Patrick for the input. I am using WindowsXP and I use the FTP functionality in Dreamweaver except when we work on sites that are load balanced across multiple servers. I am in favor of relative links but a lot of the sites I pull down to work on are not. I use the hosts file to make entries that resolve to local IP addresses. For example, in this case I might add: 127.0.0.2 www.somedomain.com Now if I flush the DNS cache and wait for a couple of minutes, my browsers will resolve to locally served content when I type in www.somedomain.com. When I am ready to upload and check results on the web I want to be able to run my switch script (which removes the above specified entry and re-flushes the cache). My problem is, it takes almost 5 minutes for my browsers to recognize the change event though ping and ipconfig /displaydns resole to the correct external IP. How do I make the change instantaneous in the browser like it is for command-line tools like ping and ipconfig? Quote
pagoda Posted January 5, 2008 Posted January 5, 2008 Greetings Again, Hmmm... I did not see where you specified the browser you are using that takes so long. However, I used to have an identical problem but only with one browser (being a web developer myself I use many browsers to ensure that my content is at least somewhat consistent). The offending browser was always MIE 6.x. Personally, I use Firefox for my own browsing and I now use MIE 7.x for development (unless a client requests an older version - but I live in a town that has the highest per capita number of Ph.D.s in the world and thus is very technically savvy - this is both good and bad ) Anyway - with MIE 7.x, Firefox *.x and Opera, Safari for Windows, Dillo for Linux, etc., etc., I do not have this problem of the network not updating when I change the hosts file. Now, that said, when I used to use MIE 6.x my only recourse was to kill the browser and reopen it after changing the hosts file. I know that sucks, but at least for me it worked. In the world of Linux or other *nixes I would simply issue a "kill -HUP NNN" where NNN was the process number to refresh the process - but I am unaware of an analog for Windows for doing this. I only mention this on the off chance that you actually DO know how to do this and perhaps this jogs something in your memory. Sorry I cannot give a more concrete answer. Just out of curiosity, if you don't mind sharing it, what does your ../etc/hosts file look like on Windows and the script you are using? If you do not want to post this publicly, feel free to PM me if you would like. I do recall once having a loop in my ../etc/hosts file on Windows that caused me huge headaches. I still have the notes about how I fixed that, so perhaps this is something similar???? Cheers, Patrick Quote
pagoda Posted January 5, 2008 Posted January 5, 2008 Greetings, A quick Google search shows what may be some interesting items for you (or may not be, or perhaps you've already seen them): 1) http://www.mvps.org/winhelp2002/hostsfaq.htm 2) http://technet.microsoft.com/en-us/library/bb727005.aspx (Straight from the "horses mouth" so to speak - Microsoft's view of things) 3) http://www.mvps.org/winhelp2002/hosts.htm (Another very good site : implies that you might want to use 127.0.0.1 for the site you are working on - I dislike this answer personally, but perhaps it is just what you need?) Cheers, Patrick Quote
adephue Posted January 5, 2008 Author Posted January 5, 2008 I am actually reformatting. My Dell Laptop just toasted its 4th HDD is two years so I got a new drive and motherboard under warranty and am in the process of setting everything back up... that said, there is not much in my hosts file right now, but I can give examples. I am using two hosts files. One is the default, the other is called hosts2 and it has all of my local development entries so it would look like this: 127.0.0.1 localhost 127.0.0.2 www.somedomain.com 127.0.0.3 www.someotherdomain.com My 'switch' script is as follows: @echo off rename hosts tmp rename hosts2 hosts rename tmp hosts2 ipconfig /flushdns So basically I have my script attached to a keyboard shortcut. I run the script (which simply swaps two versions of the hosts file) and command-line utilities pickup the dns change immediately. Regardless of what browser I use (have tried FF 1.5 & 2, IE6 & 7) it takes several minutes for the page to load from the correct source. Quote
pagoda Posted January 5, 2008 Posted January 5, 2008 Hi, Here are a couple of potential things to try to see what the results are - I see that you've altered the registry for TTL for connections (which defaults to 86400 sec = 1 day) but perhaps you have not tried this - in: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DNSCache\Parameters create a new DWORD value of MaxNegativeCacheTtl and set it to something very small (it defaults to 300 s or 5 minutes - this is of the order of the issue you reported, which is why this stood out). This sets the TTL for _negative_ responses (i.e. those that do not connect using the default DNS entries. I mention this strictly based on the similarity of the order of magnitude of the default time and the time you report you are having problems with your browsers refreshing to the correct site. Another possibility is: do you perchance have HostnameLookups set in your Apache configuration file? If so, this will definitely degrade performance, especially when switching between a FQDN and a fictitious domain name you use for development. Other than these things, I am unable to come up with anything. I tried to reproduce the result on my machine, but could not. I even seriously (intentionally) messed up my DNS settings and then set various common websites (that were already in "ipconfig /displaydns" - such as google, and a bunch of others) but again could not reproduce the effect. BTW - I incorrectly stated that in Windows hosts files you could only use one domain name, some people claim (as does Microsoft) that you can use an "alias" of the form: 192.168.0.10 mymachine.somewhere.com mymachine That said, this has always failed for me for some reason. Anyway - once you get your machine to a stable state, and can reproduce the error (perhaps you already can) then you might look at the output of "ipconfig /displaydns" just to see what's in there. I would be remiss if I also did not mention that one my machine, given that I route everything through a Linux box, I have no Primary DNS Suffix (which I believe is similar to the information in /etc/resolv.conf on a *nix machine). In other words, my machine has a name of the form "mymachine" and not "mymachine.subdomain.tld". I do, however, map mymachine.subdomain.tld to 127.0.0.1 in Windows ../etc/hosts. I do not know if this is salient information or not. I'm about to check out for the day but will think on this and check back tomorrow. Cheers, Patrick PS: What does "tracert www.somewhere.com" show both before and after running your script? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.